Skip to content

Commit 8497c36

Browse files
committedSep 22, 2020
8253465: jextract should generate constant classes as package private
Reviewed-by: jvernee
1 parent 96b6117 commit 8497c36

File tree

9 files changed

+7559
-7201
lines changed

9 files changed

+7559
-7201
lines changed
 

‎src/jdk.incubator.jextract/share/classes/README

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ jextract was run using "sh extract.sh" on Mac OS.
44
Manual modifications:
55

66
* GNU/CP copyright header added
7-
* CSupport.SysV.* imports replaced by CSupport.* (platform independent C layouts)
87
* Generated C_LONG layouts are replaced with C_LONGLONG for portability
98
* Index_h$constants$N classes were renamed to be Index_h$constants_N
109
* Index_h$constants_0.libName was manually added to handle platform dependency of

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/Index_h$constants.java ‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/C.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@
2424
*
2525
*/
2626

27-
// Generated by jextract
28-
2927
package jdk.internal.clang.libclang;
28+
// Generated by jextract
3029

31-
import java.lang.invoke.MethodHandle;
32-
import java.lang.invoke.VarHandle;
33-
import jdk.incubator.foreign.*;
34-
import jdk.incubator.foreign.MemoryLayout.PathElement;
35-
import static jdk.incubator.foreign.CLinker.*;
30+
import java.lang.annotation.Documented;
31+
import java.lang.annotation.ElementType;
32+
import java.lang.annotation.Retention;
33+
import java.lang.annotation.RetentionPolicy;
34+
import java.lang.annotation.Target;
3635

37-
public final class Index_h$constants extends Index_h$constants_2 {
36+
/**
37+
* Annotation to indicate C types
38+
*/
39+
@Target({ ElementType.TYPE_USE })
40+
@Retention(RetentionPolicy.RUNTIME)
41+
@Documented
42+
public @interface C {
43+
/**
44+
* The C type associated with a given Java type
45+
* @return The C type associated with a given Java type
46+
*/
47+
String value();
3848
}
39-

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/Index_h$constants_0.java

+2,188-1,074
Large diffs are not rendered by default.

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/Index_h$constants_1.java

+2,404-2,798
Large diffs are not rendered by default.

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/Index_h$constants_2.java

-648
This file was deleted.

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/Index_h.java

+2,923-2,643
Large diffs are not rendered by default.

‎src/jdk.incubator.jextract/share/classes/jdk/internal/clang/libclang/RuntimeHelper.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
*
2525
*/
2626

27-
// Generated by jextract
28-
2927
package jdk.internal.clang.libclang;
28+
// Generated by jextract
3029

3130
import jdk.incubator.foreign.Addressable;
3231
import jdk.incubator.foreign.CLinker;
@@ -41,13 +40,12 @@
4140
import java.lang.invoke.MethodType;
4241
import java.io.File;
4342
import java.nio.file.Path;
43+
import java.nio.charset.StandardCharsets;
4444
import java.util.Arrays;
4545
import java.util.Optional;
4646
import java.util.stream.Stream;
4747

48-
import static jdk.incubator.foreign.CLinker.C_DOUBLE;
49-
import static jdk.incubator.foreign.CLinker.C_LONGLONG;
50-
import static jdk.incubator.foreign.CLinker.C_POINTER;
48+
import static jdk.incubator.foreign.CLinker.*;
5149

5250
final class RuntimeHelper {
5351
private RuntimeHelper() {}
@@ -77,10 +75,6 @@ static final MemorySegment lookupGlobalVariable(LibraryLookup[] LIBRARIES, Strin
7775
.withOwnerThread(null))).orElse(null);
7876
}
7977

80-
static final MemorySegment nonCloseableNonTransferableSegment(MemorySegment seg) {
81-
return seg.withAccessModes(seg.accessModes() & ~MemorySegment.CLOSE & ~MemorySegment.HANDOFF);
82-
}
83-
8478
static final MethodHandle downcallHandle(LibraryLookup[] LIBRARIES, String name, String desc, FunctionDescriptor fdesc, boolean variadic) {
8579
return lookup(LIBRARIES, name).map(
8680
addr -> {
@@ -102,11 +96,19 @@ static final <Z> MemorySegment upcallStub(Class<Z> fi, Z z, FunctionDescriptor f
10296
}
10397
}
10498

105-
static final MemorySegment asArrayRestricted(MemoryAddress addr, MemoryLayout layout, int numElements) {
106-
return nonCloseableNonTransferableSegment(addr.asSegmentRestricted(numElements * layout.byteSize()));
99+
static final MemorySegment nonCloseableNonTransferableSegment(MemorySegment seg) {
100+
return seg.withAccessModes(seg.accessModes() & ~MemorySegment.CLOSE & ~MemorySegment.HANDOFF);
101+
}
102+
103+
static MemorySegment asArrayRestricted(MemoryAddress addr, MemoryLayout layout, int numElements) {
104+
return nonCloseableSegment(addr.asSegmentRestricted(numElements * layout.byteSize()));
105+
}
106+
107+
// Internals only below this point
108+
private static final MemorySegment nonCloseableSegment(MemorySegment seg) {
109+
return seg.withAccessModes(seg.accessModes() & ~MemorySegment.CLOSE);
107110
}
108111

109-
// Internals below this point
110112
private static final Optional<LibraryLookup.Symbol> lookup(LibraryLookup[] LIBRARIES, String sym) {
111113
return Stream.of(LIBRARIES)
112114
.flatMap(l -> l.lookup(sym).stream())

‎src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/ClassConstantHelper.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,7 @@ private static String toInternalName(String className) {
205205

206206
private void classBegin(String baseClassName, boolean isFinal) {
207207
String baseName = baseClassName != null ? toInternalName(baseClassName) : INTR_OBJECT;
208-
int mods = ACC_PUBLIC;
209-
if (isFinal) {
210-
mods |= ACC_FINAL;
211-
}
208+
int mods = isFinal? ACC_FINAL : 0;
212209
cw.visit(V15, mods, internalClassName, null, baseName, null);
213210
}
214211

@@ -513,7 +510,7 @@ private static void emitConDouble(MethodVisitor mv, double value) {
513510
private DirectMethodHandleDesc emitGetter(String name, Class<?> type, Consumer<MethodVisitor> action) {
514511
return pool.computeIfAbsent(name, nameKey -> {
515512
MethodType mt = methodType(type);
516-
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, nameKey, mt.descriptorString(), null, null);
513+
MethodVisitor mv = cw.visitMethod(ACC_STATIC | ACC_FINAL, nameKey, mt.descriptorString(), null, null);
517514
mv.visitCode();
518515
action.accept(mv);
519516
emitReturn(mv, type);

‎src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/SourceConstantHelper.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
// generates ConstantHelper as java source
5454
class SourceConstantHelper implements ConstantHelper {
55-
private static final String PACKAGE_FINAL_MODS = "static final ";
55+
private static final String PKG_STATIC_FINAL_MODS = "static final ";
5656

5757
// set of names generates already
5858
private static final Map<String, DirectMethodHandleDesc> namesGenerated = new HashMap<>();
@@ -199,7 +199,6 @@ private void emitConstructor() {
199199
private void classBegin(String[] libraryNames, String baseClassName, boolean isFinal) {
200200
addPackagePrefix(pkgName);
201201
addImportSection();
202-
append("public ");
203202
if (isFinal) {
204203
append("final ");
205204
}
@@ -231,7 +230,7 @@ private DirectMethodHandleDesc getGetterDesc(String name, Class<?> type) {
231230
private DirectMethodHandleDesc emitGetter(String name, Class<?> type, String value) {
232231
incrAlign();
233232
indent();
234-
append(JavaSourceBuilder.PUB_MODS);
233+
append(PKG_STATIC_FINAL_MODS);
235234
append(type.getName());
236235
append(' ');
237236
append(name);
@@ -300,7 +299,7 @@ private String emitMethodHandleField(String javaName, String nativeName, MethodT
300299
incrAlign();
301300
String fieldName = getMethodHandleFieldName(javaName);
302301
indent();
303-
append(PACKAGE_FINAL_MODS + "MethodHandle ");
302+
append(PKG_STATIC_FINAL_MODS + "MethodHandle ");
304303
append(fieldName + " = RuntimeHelper.downcallHandle(\n");
305304
incrAlign();
306305
indent();
@@ -335,7 +334,7 @@ private String emitVarHandleField(String javaName, String nativeName, Class<?> t
335334
}
336335
indent();
337336
String fieldName = getVarHandleFieldName(javaName);
338-
append(PACKAGE_FINAL_MODS + "VarHandle " + fieldName + " = ");
337+
append(PKG_STATIC_FINAL_MODS + "VarHandle " + fieldName + " = ");
339338
if (isAddr) {
340339
append("MemoryHandles.asAddressVarHandle(");
341340
}
@@ -361,7 +360,7 @@ private String emitLayoutField(String javaName, MemoryLayout layout) {
361360
String fieldName = getLayoutFieldName(javaName);
362361
incrAlign();
363362
indent();
364-
append(PACKAGE_FINAL_MODS + "MemoryLayout " + fieldName + " = ");
363+
append(PKG_STATIC_FINAL_MODS + "MemoryLayout " + fieldName + " = ");
365364
emitLayoutString(layout);
366365
append(";\n");
367366
decrAlign();
@@ -414,7 +413,7 @@ private String emitFunctionDescField(String javaName, FunctionDescriptor desc) {
414413
indent();
415414
String fieldName = getFunctionDescFieldName(javaName);
416415
final boolean noArgs = desc.argumentLayouts().isEmpty();
417-
append(PACKAGE_FINAL_MODS);
416+
append(PKG_STATIC_FINAL_MODS);
418417
append("FunctionDescriptor ");
419418
append(fieldName);
420419
append(" = ");
@@ -453,7 +452,7 @@ private String emitConstantSegment(String javaName, Object value) {
453452
incrAlign();
454453
indent();
455454
String fieldName = getConstantSegmentFieldName(javaName);
456-
append(PACKAGE_FINAL_MODS);
455+
append(PKG_STATIC_FINAL_MODS);
457456
append("MemorySegment ");
458457
append(fieldName);
459458
append(" = CLinker.toCString(\"");
@@ -470,7 +469,7 @@ private String emitConstantAddress(String javaName, Object value) {
470469
incrAlign();
471470
indent();
472471
String fieldName = getConstantAddressFieldName(javaName);
473-
append(PACKAGE_FINAL_MODS);
472+
append(PKG_STATIC_FINAL_MODS);
474473
append("MemoryAddress ");
475474
append(fieldName);
476475
append(" = MemoryAddress.ofLong(");
@@ -528,7 +527,7 @@ private String emitSegmentField(String javaName, String nativeName, MemoryLayout
528527
incrAlign();
529528
indent();
530529
String fieldName = getSegmentFieldName(javaName);
531-
append(PACKAGE_FINAL_MODS);
530+
append(PKG_STATIC_FINAL_MODS);
532531
append("MemorySegment ");
533532
append(fieldName);
534533
append(" = ");
@@ -545,7 +544,7 @@ private String emitSegmentField(String javaName, String nativeName, MemoryLayout
545544
private void emitLibraries(String[] libraryNames) {
546545
incrAlign();
547546
indent();
548-
append(PACKAGE_FINAL_MODS);
547+
append(PKG_STATIC_FINAL_MODS);
549548
append("LibraryLookup[] LIBRARIES = RuntimeHelper.libraries(new String[] {\n");
550549
incrAlign();
551550
for (String lib : libraryNames) {

0 commit comments

Comments
 (0)
Please sign in to comment.