8290234: [JVMCI] use JVMCIKlassHandle to protect raw Klass* values from concurrent G1 scanning

Reviewed-by: kvn, never
This commit is contained in:
Doug Simon 2022-07-13 19:15:53 +00:00
parent 5e3ecff7a6
commit 74ac5df96f
3 changed files with 16 additions and 13 deletions

View File

@ -880,8 +880,15 @@ final class CompilerToVM {
return getResolvedJavaType0(base, displacement, compressed);
}
HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean compressed) {
return getResolvedJavaType0(null, displacement, compressed);
/**
* Reads a {@code Klass*} from {@code address} (i.e., {@code address} is a {@code Klass**}
* value) and wraps it in a {@link HotSpotResolvedObjectTypeImpl}. This VM call must be used for
* any {@code Klass*} value not known to be already wrapped in a
* {@link HotSpotResolvedObjectTypeImpl}. The VM call is necessary so that the {@code Klass*} is
* wrapped in a {@code JVMCIKlassHandle} to protect it from the concurrent scanning done by G1.
*/
HotSpotResolvedObjectTypeImpl getResolvedJavaType(long address) {
return getResolvedJavaType0(null, address, false);
}
/**

View File

@ -308,11 +308,7 @@ final class HotSpotMethodData {
private HotSpotResolvedObjectTypeImpl readKlass(int position, int offsetInBytes) {
long fullOffsetInBytes = state.computeFullOffset(position, offsetInBytes);
long klassPointer = UNSAFE.getAddress(methodDataPointer + fullOffsetInBytes);
if (klassPointer == 0) {
return null;
}
return runtime().fromMetaspace(klassPointer);
return compilerToVM().getResolvedJavaType(methodDataPointer + fullOffsetInBytes);
}
/**

View File

@ -35,6 +35,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Executable;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.Objects;
import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
@ -89,12 +90,11 @@ final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSp
*/
private static HotSpotResolvedObjectTypeImpl getHolder(long metaspaceHandle) {
HotSpotVMConfig config = config();
long metaspaceMethod = UNSAFE.getLong(metaspaceHandle);
assert metaspaceMethod != 0 : metaspaceHandle;
final long metaspaceConstMethod = UNSAFE.getAddress(metaspaceMethod + config.methodConstMethodOffset);
final long metaspaceConstantPool = UNSAFE.getAddress(metaspaceConstMethod + config.constMethodConstantsOffset);
long klassPointer = UNSAFE.getAddress(metaspaceConstantPool + config.constantPoolHolderOffset);
return runtime().fromMetaspace(klassPointer);
long methodPointer = UNSAFE.getLong(metaspaceHandle);
assert methodPointer != 0 : metaspaceHandle;
final long constMethodPointer = UNSAFE.getAddress(methodPointer + config.methodConstMethodOffset);
final long constantPoolPointer = UNSAFE.getAddress(constMethodPointer + config.constMethodConstantsOffset);
return Objects.requireNonNull(compilerToVM().getResolvedJavaType(constantPoolPointer + config.constantPoolHolderOffset));
}
/**