Skip to content

Commit edc7af4

Browse files
[GR-45112] Ensure @RawStructure fields have getters and setters.
PullRequest: graal/14146
2 parents da53c0d + 8e823aa commit edc7af4

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsVirtualMemoryProvider.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,28 @@ private static void specifyAlignment(MEM_EXTENDED_PARAMETER extendedParameter, M
228228
* the memory layout that the native code expects, it is sufficient to ensure the correct
229229
* order of the fields, which is easily done by prefixing the field names.
230230
*/
231-
extendedParameter.f1Type(MemExtendedParameterAddressRequirements);
232-
extendedParameter.f2Pointer(addressRequirements.rawValue());
233-
addressRequirements.f1LowestStartingAddress(WordFactory.nullPointer());
234-
addressRequirements.f2HighestEndingAddress(WordFactory.nullPointer());
235-
addressRequirements.f3Alignment(alignment);
231+
extendedParameter.setF1Type(MemExtendedParameterAddressRequirements);
232+
extendedParameter.setF2Pointer(addressRequirements.rawValue());
233+
addressRequirements.setF1LowestStartingAddress(WordFactory.nullPointer());
234+
addressRequirements.setF2HighestEndingAddress(WordFactory.nullPointer());
235+
addressRequirements.setF3Alignment(alignment);
236236
}
237237

238238
/** Represents an extended parameter for a function that manages virtual memory. */
239239
@RawStructure
240240
private interface MEM_EXTENDED_PARAMETER extends PointerBase {
241241
/* This structure must exactly match the memory layout expected by the native code. */
242242
@RawField
243-
void f1Type(long value);
243+
void setF1Type(long value);
244244

245245
@RawField
246-
void f2Pointer(long value);
246+
long getF1Type();
247+
248+
@RawField
249+
void setF2Pointer(long value);
250+
251+
@RawField
252+
long getF2Pointer();
247253
}
248254

249255
/** MEM_EXTENDED_PARAMETER_TYPE enumeration Constants. */
@@ -257,13 +263,22 @@ private interface MEM_EXTENDED_PARAMETER extends PointerBase {
257263
private interface MEM_ADDRESS_REQUIREMENTS extends PointerBase {
258264
/* This structure must exactly match the memory layout expected by the native code. */
259265
@RawField
260-
void f1LowestStartingAddress(PointerBase value);
266+
void setF1LowestStartingAddress(PointerBase value);
267+
268+
@RawField
269+
PointerBase getF1LowestStartingAddress();
270+
271+
@RawField
272+
void setF2HighestEndingAddress(PointerBase value);
273+
274+
@RawField
275+
PointerBase getF2HighestEndingAddress();
261276

262277
@RawField
263-
void f2HighestEndingAddress(PointerBase value);
278+
void setF3Alignment(UnsignedWord value);
264279

265280
@RawField
266-
void f3Alignment(UnsignedWord value);
281+
UnsignedWord getF3Alignment();
267282
}
268283

269284
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
534534
log.string("General purpose register values:").indent(true);
535535
RegisterDumper.singleton().dumpRegisters(log, context.getRegisterContext(), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
536536
log.indent(false);
537-
} else if (CalleeSavedRegisters.supportedByPlatform() && context.frameHasCalleeSavedRegisters()) {
537+
} else if (CalleeSavedRegisters.supportedByPlatform() && context.getFrameHasCalleeSavedRegisters()) {
538538
CalleeSavedRegisters.singleton().dumpRegisters(log, context.getStackPointer(), printLocationInfo, allowJavaHeapAccess, allowUnsafeOperations);
539539
}
540540
}
@@ -1037,7 +1037,7 @@ public interface ErrorContext extends PointerBase {
10371037
void setRegisterContext(RegisterDumper.Context value);
10381038

10391039
@RawField
1040-
boolean frameHasCalleeSavedRegisters();
1040+
boolean getFrameHasCalleeSavedRegisters();
10411041

10421042
@RawField
10431043
void setFrameHasCalleeSavedRegisters(boolean value);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.graalvm.compiler.word.Word;
2828
import org.graalvm.nativeimage.c.function.CodePointer;
2929
import org.graalvm.nativeimage.c.struct.RawField;
30+
import org.graalvm.nativeimage.c.struct.RawFieldOffset;
3031
import org.graalvm.nativeimage.c.struct.RawStructure;
3132
import org.graalvm.word.UnsignedWord;
3233

@@ -36,6 +37,7 @@
3637
import com.oracle.svm.core.deopt.SubstrateInstalledCode;
3738
import com.oracle.svm.core.heap.RuntimeCodeInfoGCSupport;
3839
import com.oracle.svm.core.util.DuplicatedInNativeCode;
40+
import com.oracle.svm.core.util.VMError;
3941

4042
import jdk.vm.ci.code.InstalledCode;
4143

@@ -246,6 +248,11 @@ interface CodeInfoImpl extends CodeInfo {
246248
@RawField
247249
Word getGCData();
248250

251+
@RawFieldOffset
252+
static int offsetOfGCData() {
253+
throw VMError.unimplemented(); // replaced
254+
}
255+
249256
@RawField
250257
void setAllObjectsAreInImageHeap(boolean value);
251258

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/info/InfoTreeBuilder.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.pointsto.meta.AnalysisMethod;
6060
import com.oracle.graal.pointsto.util.GraalAccess;
6161
import com.oracle.svm.core.c.struct.PinnedObjectField;
62+
import com.oracle.svm.core.util.VMError;
6263
import com.oracle.svm.hosted.c.BuiltinDirectives;
6364
import com.oracle.svm.hosted.c.NativeCodeContext;
6465
import com.oracle.svm.hosted.c.NativeLibraries;
@@ -345,12 +346,40 @@ private void createRawStructInfo(ResolvedJavaType type) {
345346
StructFieldInfo fieldInfo = new StructFieldInfo(entry.getKey(), elementKind(entry.getValue()));
346347
fieldInfo.adoptChildren(entry.getValue());
347348
structInfo.adoptChild(fieldInfo);
349+
verifyRawStructFieldAccessors(fieldInfo);
348350
}
349351

350352
nativeCodeInfo.adoptChild(structInfo);
351353
nativeLibs.registerElementInfo(type, structInfo);
352354
}
353355

356+
private void verifyRawStructFieldAccessors(StructFieldInfo fieldInfo) {
357+
boolean hasGetter = false;
358+
boolean hasSetter = false;
359+
for (ElementInfo child : fieldInfo.getChildren()) {
360+
if (child instanceof AccessorInfo) {
361+
AccessorKind kind = ((AccessorInfo) child).getAccessorKind();
362+
if (kind == AccessorKind.GETTER) {
363+
hasGetter = true;
364+
} else if (kind == AccessorKind.SETTER) {
365+
hasSetter = true;
366+
} else if (kind == AccessorKind.ADDRESS || kind == AccessorKind.OFFSET) {
367+
hasGetter = true;
368+
hasSetter = true;
369+
} else {
370+
throw VMError.shouldNotReachHere("Unexpected accessor kind: " + kind);
371+
}
372+
}
373+
}
374+
375+
if (!hasSetter) {
376+
nativeLibs.addError(String.format("%s.%s does not have a setter. @RawStructure fields need both a getter and a setter.", fieldInfo.getParent().getName(), fieldInfo.getName()));
377+
}
378+
if (!hasGetter) {
379+
nativeLibs.addError(String.format("%s.%s does not have a getter. @RawStructure fields need both a getter and a setter.", fieldInfo.getParent().getName(), fieldInfo.getName()));
380+
}
381+
}
382+
354383
private boolean hasLocationIdentityParameter(ResolvedJavaMethod method) {
355384
int parameterCount = getParameterCount(method);
356385
if (parameterCount == 0) {

0 commit comments

Comments
 (0)