Skip to content

Commit 3865b64

Browse files
committed
Move unsafe allocation tracing to the fast path
1 parent 66da937 commit 3865b64

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/SubstrateAllocationSnippets.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Arrays;
3737
import java.util.Map;
3838

39+
import com.oracle.svm.core.metadata.MetadataTracer;
3940
import org.graalvm.nativeimage.ImageSingletons;
4041
import org.graalvm.word.LocationIdentity;
4142
import org.graalvm.word.UnsignedWord;
@@ -122,10 +123,12 @@ public class SubstrateAllocationSnippets extends AllocationSnippets {
122123
public static final LocationIdentity[] GC_LOCATIONS = new LocationIdentity[]{TLAB_START_IDENTITY, TLAB_TOP_IDENTITY, TLAB_END_IDENTITY, IdentityHashCodeSupport.IDENTITY_HASHCODE_SALT_LOCATION};
123124

124125
private static final SubstrateForeignCallDescriptor NEW_MULTI_ARRAY = SnippetRuntime.findForeignCall(SubstrateAllocationSnippets.class, "newMultiArrayStub", NO_SIDE_EFFECT);
126+
private static final SubstrateForeignCallDescriptor TRACE_UNSAFE_ALLOCATION = SnippetRuntime.findForeignCall(SubstrateAllocationSnippets.class, "traceUnsafeAllocation", NO_SIDE_EFFECT);
125127
private static final SubstrateForeignCallDescriptor SLOW_PATH_HUB_OR_UNSAFE_INSTANTIATE_ERROR = SnippetRuntime.findForeignCall(SubstrateAllocationSnippets.class,
126128
"slowPathHubOrUnsafeInstantiationError", NO_SIDE_EFFECT);
127129
private static final SubstrateForeignCallDescriptor ARRAY_HUB_ERROR = SnippetRuntime.findForeignCall(SubstrateAllocationSnippets.class, "arrayHubErrorStub", NO_SIDE_EFFECT);
128-
private static final SubstrateForeignCallDescriptor[] FOREIGN_CALLS = new SubstrateForeignCallDescriptor[]{NEW_MULTI_ARRAY, SLOW_PATH_HUB_OR_UNSAFE_INSTANTIATE_ERROR, ARRAY_HUB_ERROR};
130+
private static final SubstrateForeignCallDescriptor[] FOREIGN_CALLS = new SubstrateForeignCallDescriptor[]{NEW_MULTI_ARRAY, TRACE_UNSAFE_ALLOCATION, SLOW_PATH_HUB_OR_UNSAFE_INSTANTIATE_ERROR,
131+
ARRAY_HUB_ERROR};
129132

130133
public void registerForeignCalls(SubstrateForeignCallsProvider foreignCalls) {
131134
foreignCalls.register(FOREIGN_CALLS);
@@ -309,6 +312,9 @@ protected Object newmultiarray(DynamicHub hub, @ConstantParameter int rank, @Con
309312
public DynamicHub validateNewInstanceClass(DynamicHub hub) {
310313
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, hub != null)) {
311314
DynamicHub nonNullHub = (DynamicHub) PiNode.piCastNonNull(hub, SnippetAnchorNode.anchor());
315+
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, MetadataTracer.enabled())) {
316+
traceUnsafeAllocationStub(TRACE_UNSAFE_ALLOCATION, DynamicHub.toClass(nonNullHub));
317+
}
312318
if (probability(EXTREMELY_FAST_PATH_PROBABILITY, nonNullHub.canUnsafeInstantiateAsInstanceFastPath())) {
313319
return nonNullHub;
314320
}
@@ -344,6 +350,15 @@ private static Object newMultiArrayRecursion(DynamicHub hub, int rank, Word dime
344350
return result;
345351
}
346352

353+
@NodeIntrinsic(value = ForeignCallWithExceptionNode.class)
354+
private static native DynamicHub traceUnsafeAllocationStub(@ConstantNodeParameter ForeignCallDescriptor descriptor, Class<?> hub);
355+
356+
/** Foreign call: {@link #TRACE_UNSAFE_ALLOCATION}. */
357+
@SubstrateForeignCallTarget(stubCallingConvention = true)
358+
private static void traceUnsafeAllocation(DynamicHub hub) {
359+
MetadataTracer.singleton().traceUnsafeAllocatedType(DynamicHub.toClass(hub));
360+
}
361+
347362
@NodeIntrinsic(value = ForeignCallWithExceptionNode.class)
348363
private static native DynamicHub slowPathHubOrUnsafeInstantiationErrorStub(@ConstantNodeParameter ForeignCallDescriptor descriptor, Class<?> hub);
349364

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,6 @@ public static Throwable getSavedException(String className) {
510510
*/
511511
public static boolean canUnsafeInstantiateAsInstance(DynamicHub hub) {
512512
Class<?> clazz = DynamicHub.toClass(hub);
513-
if (MetadataTracer.enabled()) {
514-
MetadataTracer.singleton().traceUnsafeAllocatedType(clazz);
515-
}
516513
RuntimeConditionSet conditionSet = null;
517514
for (var singleton : layeredSingletons()) {
518515
conditionSet = singleton.unsafeInstantiatedClasses.get(clazz);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/metadata/MetadataTracer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public List<Class<? extends Feature>> getRequiredFeatures() {
633633
}
634634

635635
@Override
636-
public void beforeAnalysis(BeforeAnalysisAccess access) {
636+
public void duringSetup(DuringSetupAccess access) {
637637
if (MetadataTracer.Options.MetadataTracingSupport.getValue()) {
638638
ImageSingletons.add(MetadataTracer.class, new MetadataTracer());
639639
RuntimeSupport.getRuntimeSupport().addInitializationHook(MetadataTracer.initializeMetadataTracingHook());

0 commit comments

Comments
 (0)