8236647: java/lang/invoke/CallSiteTest.java failed with InvocationTargetException in Graal mode

Reviewed-by: kvn
This commit is contained in:
Dean Long 2020-06-15 17:17:28 -07:00
parent f968f32789
commit 02cec3470f
2 changed files with 32 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,6 +54,7 @@ public class HotSpotMethodHandleAccessProvider implements MethodHandleAccessProv
final ResolvedJavaField methodHandleFormField;
final ResolvedJavaField lambdaFormVmentryField;
final HotSpotResolvedJavaField callSiteTargetField;
final HotSpotResolvedJavaField constantCallSiteFrozenField;
final ResolvedJavaField methodField;
final HotSpotResolvedJavaField vmtargetField;
@ -94,6 +95,9 @@ public class HotSpotMethodHandleAccessProvider implements MethodHandleAccessProv
ResolvedJavaType callSiteType = resolveType("Ljava/lang/invoke/CallSite;");
callSiteTargetField = (HotSpotResolvedJavaField) findFieldInClass(callSiteType, "target", methodHandleType);
ResolvedJavaType constantCallSiteType = resolveType("Ljava/lang/invoke/ConstantCallSite;");
ResolvedJavaType booleanType = resolveType("Z");
constantCallSiteFrozenField = (HotSpotResolvedJavaField) findFieldInClass(constantCallSiteType, "isFrozen", booleanType);
} catch (Throwable ex) {
throw new JVMCIError(ex);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -65,18 +65,39 @@ abstract class HotSpotObjectConstantImpl implements HotSpotObjectConstant {
@Override
public abstract int getIdentityHashCode();
static class Fields {
// Initializing these too early causes a hang, so do it here in a subclass
static final HotSpotResolvedJavaField callSiteTargetField = HotSpotMethodHandleAccessProvider.Internals.instance().callSiteTargetField;
static final HotSpotResolvedJavaField constantCallSiteFrozenField = HotSpotMethodHandleAccessProvider.Internals.instance().constantCallSiteFrozenField;
}
private boolean isFullyInitializedConstantCallSite() {
if (!runtime().getConstantCallSite().isInstance(this)) {
return false;
}
// read ConstantCallSite.isFrozen as a volatile field
boolean isFrozen = readFieldValue(Fields.constantCallSiteFrozenField, true /* volatile */).asBoolean();
// isFrozen true implies fully-initialized
return isFrozen;
}
private HotSpotObjectConstantImpl readTarget() {
// read CallSite.target as a volatile field
return (HotSpotObjectConstantImpl) readFieldValue(Fields.callSiteTargetField, true /* volatile */);
}
@Override
public JavaConstant getCallSiteTarget(Assumptions assumptions) {
if (runtime().getCallSite().isInstance(this)) {
HotSpotObjectConstantImpl target = (HotSpotObjectConstantImpl) runtime().getHostJVMCIBackend().getConstantReflection().readFieldValue(
HotSpotMethodHandleAccessProvider.Internals.instance().callSiteTargetField, this);
if (!runtime().getConstantCallSite().isInstance(this)) {
// For ConstantCallSites, we need to read "isFrozen" before reading "target"
// isFullyInitializedConstantCallSite() reads "isFrozen"
if (!isFullyInitializedConstantCallSite()) {
if (assumptions == null) {
return null;
}
assumptions.record(new Assumptions.CallSiteTargetValue(this, target));
assumptions.record(new Assumptions.CallSiteTargetValue(this, readTarget()));
}
return target;
return readTarget();
}
return null;
}