Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[GR-39730] Use JVMCIKlassHandle to protect raw Klass* values from con…
Browse files Browse the repository at this point in the history
…current G1 scanning.

PullRequest: labsjdk-ce-17/56
  • Loading branch information
dougxc committed Jul 12, 2022
2 parents d789764 + 5d0394e commit 02c4bcd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,17 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(HotSpotObjectConstantImpl base
return getResolvedJavaType0(base, 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);
}

/**
* Return the size of the HotSpot ProfileData* pointed at by {@code position}. If
* {@code position} is outside the space of the MethodData then an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,7 @@ private HotSpotResolvedJavaMethod readMethod(int position, int offsetInBytes) {

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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 02c4bcd

Please sign in to comment.