Skip to content

Commit

Permalink
Check if the VM supports fetching static fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vjovanov committed Oct 15, 2019
1 parent ddcb4da commit 20e30b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,32 @@ private ResolvedJavaField getStaticFieldUnsafeAccess(ConstantReflectionProvider
return findStaticFieldWithOffset(staticReceiverType, offsetConstant.asLong(), accessKind);
}

/**
* NOTE GR-18873: this is a HotSpot-specific copy-pase implementation derived from
* {@code jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl#findStaticFieldWithOffset}.
*/
private static ResolvedJavaField findStaticFieldWithOffset(ResolvedJavaType type, long offset, JavaKind expectedEntryKind) {
ResolvedJavaField[] declaredFields = type.getStaticFields();
return findFieldWithOffset(offset, expectedEntryKind, declaredFields);
try {
ResolvedJavaField[] declaredFields = type.getStaticFields();
return findFieldWithOffset(offset, expectedEntryKind, declaredFields);
} catch (UnsupportedOperationException e) {
return null;
}
}

/**
* NOTE GR-18873: this is a HotSpot-specific copy-paste implementation derived from
* {@code jdk.vm.ci.hotspot.HotSpotResolvedObjectTypeImpl#findStaticFieldWithOffset}.
*/
private static ResolvedJavaField findFieldWithOffset(long offset, JavaKind expectedEntryKind, ResolvedJavaField[] declaredFields) {
for (ResolvedJavaField field : declaredFields) {
long resolvedFieldOffset = field.getOffset();
// @formatter:off
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN &&
expectedEntryKind.isPrimitive() &&
!expectedEntryKind.equals(JavaKind.Void) &&
field.getJavaKind().isPrimitive()) {
resolvedFieldOffset +=
field.getJavaKind().getByteCount() -
expectedEntryKind.isPrimitive() &&
!expectedEntryKind.equals(JavaKind.Void) &&
field.getJavaKind().isPrimitive()) {
resolvedFieldOffset += field.getJavaKind().getByteCount() -
Math.min(field.getJavaKind().getByteCount(), 4 + expectedEntryKind.getByteCount());
}
if (resolvedFieldOffset == offset) {
return field;
}
// @formatter:on
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void guarantee(boolean condition, String msg) {
}

public static RuntimeException unimplemented() {
throw new HostedError("unimplemented");
throw new UnsupportedOperationException("unimplemented");
}

public static RuntimeException unsupportedFeature(String msg) {
Expand Down

0 comments on commit 20e30b7

Please sign in to comment.