Skip to content

Commit bc293be

Browse files
committed
Pass data more directly to AllocationTracing for InlinedMethodNode
1 parent 8710ef2 commit bc293be

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ public static AllocateNode create() {
636636
@Specialization(guards = "!rubyClass.isSingleton")
637637
protected RubyBasicObject allocate(RubyClass rubyClass) {
638638
final RubyBasicObject instance = new RubyBasicObject(rubyClass, getLanguage().basicObjectShape);
639-
AllocationTracing.traceBasicObjectAllocation(instance, rubyClass, this);
639+
AllocationTracing.traceInlined(instance, "Class", "__allocate__", this);
640640
return instance;
641641
}
642642

src/main/java/org/truffleruby/language/objects/AllocationTracing.java

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.truffleruby.RubyLanguage;
1515
import org.truffleruby.core.inlined.InlinedDispatchNode;
1616
import org.truffleruby.core.inlined.InlinedMethodNode;
17-
import org.truffleruby.core.klass.RubyClass;
1817
import org.truffleruby.core.objectspace.ObjectSpaceManager;
1918
import org.truffleruby.core.string.RubyString;
2019
import org.truffleruby.core.string.StringOperations;
@@ -50,45 +49,42 @@ public static void trace(RubyLanguage language, RubyContext context, RubyDynamic
5049
traceObject(language, context, instance, node);
5150
}
5251

53-
public static void traceBasicObjectAllocation(RubyDynamicObject instance, RubyClass rubyClass,
52+
private static void traceObject(RubyLanguage language, RubyContext context, Object instance, Node currentNode) {
53+
truffleTracing(language, instance);
54+
55+
if (context.getObjectSpaceManager().isTracing(language)) {
56+
traceBoundary(language, context, instance, currentNode);
57+
}
58+
}
59+
60+
public static void traceInlined(RubyDynamicObject instance, String className, String allocatingMethod,
5461
InlinedMethodNode node) {
55-
RubyLanguage language = node.getLanguage();
56-
RubyContext context = node.getContext();
57-
58-
if (!(node.getParent() instanceof InlinedDispatchNode)) {
59-
traceObject(language, context, instance, node);
60-
} else {
61-
CompilerAsserts.partialEvaluationConstant(language);
62-
63-
final AllocationReporter allocationReporter = language.getAllocationReporter();
64-
if (allocationReporter.isActive()) {
65-
allocationReporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
66-
allocationReporter.onReturnValue(instance, 0, AllocationReporter.SIZE_UNKNOWN);
67-
}
62+
final RubyLanguage language = node.getLanguage();
63+
final RubyContext context = node.getContext();
64+
65+
truffleTracing(language, instance);
6866

69-
if (context.getObjectSpaceManager().isTracing(language)) {
70-
traceInlineBoundary(language, context, instance, rubyClass, node);
67+
if (context.getObjectSpaceManager().isTracing(language)) {
68+
if (!(node.getParent() instanceof InlinedDispatchNode)) {
69+
traceBoundary(language, context, instance, node);
70+
} else {
71+
traceInlineBoundary(language, context, instance, className, allocatingMethod, node);
7172
}
7273
}
7374
}
7475

75-
private static void traceObject(RubyLanguage language, RubyContext context, Object instance, Node currentNode) {
76+
private static void truffleTracing(RubyLanguage language, Object instance) {
7677
CompilerAsserts.partialEvaluationConstant(language);
7778

7879
final AllocationReporter allocationReporter = language.getAllocationReporter();
7980
if (allocationReporter.isActive()) {
8081
allocationReporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
8182
allocationReporter.onReturnValue(instance, 0, AllocationReporter.SIZE_UNKNOWN);
8283
}
83-
84-
if (context.getObjectSpaceManager().isTracing(language)) {
85-
traceBoundary(language, context, instance, currentNode);
86-
}
8784
}
8885

8986
@TruffleBoundary
90-
private static void traceBoundary(RubyLanguage language, RubyContext context, Object object,
91-
Node currentNode) {
87+
private static void traceBoundary(RubyLanguage language, RubyContext context, Object object, Node currentNode) {
9288
final ObjectSpaceManager objectSpaceManager = context.getObjectSpaceManager();
9389
if (!objectSpaceManager.isTracingPaused()) {
9490
objectSpaceManager.setTracingPaused(true);
@@ -102,12 +98,12 @@ private static void traceBoundary(RubyLanguage language, RubyContext context, Ob
10298

10399
@TruffleBoundary
104100
private static void traceInlineBoundary(RubyLanguage language, RubyContext context, RubyDynamicObject instance,
105-
RubyClass klass, RubyContextSourceNode node) {
101+
String className, String allocatingMethod, RubyContextSourceNode node) {
106102
final ObjectSpaceManager objectSpaceManager = context.getObjectSpaceManager();
107103
if (!objectSpaceManager.isTracingPaused()) {
108104
objectSpaceManager.setTracingPaused(true);
109105
try {
110-
callTraceInlineAllocation(language, context, instance, klass, node);
106+
callTraceInlineAllocation(language, context, instance, className, allocatingMethod, node);
111107
} finally {
112108
objectSpaceManager.setTracingPaused(false);
113109
}
@@ -125,24 +121,22 @@ private static void callTraceAllocation(RubyLanguage language, RubyContext conte
125121

126122
final Object allocatingSelf = RubyArguments.getSelf(allocatingFrame);
127123
final String allocatingMethod = RubyArguments.getMethod(allocatingFrame).getName();
128-
final String className = LogicalClassNode.getUncached().execute(allocatingSelf).fields
129-
.getName();
124+
final String className = LogicalClassNode.getUncached().execute(allocatingSelf).fields.getName();
130125

131-
callAllocationTrace(language, context, object, allocatingSourceSection, allocatingMethod, className);
126+
callAllocationTrace(language, context, object, allocatingSourceSection, className, allocatingMethod);
132127
}
133128

134129
@TruffleBoundary
135130
private static void callTraceInlineAllocation(RubyLanguage language, RubyContext context,
136-
RubyDynamicObject instance, RubyClass klass, RubyContextSourceNode node) {
131+
RubyDynamicObject instance, String className, String allocatingMethod, RubyContextSourceNode node) {
137132
final SourceSection allocatingSourceSection = context
138133
.getCallStack()
139134
.getTopMostUserSourceSection(node.getEncapsulatingSourceSection());
140-
141-
callAllocationTrace(language, context, instance, allocatingSourceSection, "__allocate__", "Class");
135+
callAllocationTrace(language, context, instance, allocatingSourceSection, className, allocatingMethod);
142136
}
143137

144138
private static void callAllocationTrace(RubyLanguage language, RubyContext context, Object object,
145-
SourceSection allocatingSourceSection, String allocatingMethod, String className) {
139+
SourceSection allocatingSourceSection, String className, String allocatingMethod) {
146140
context.send(
147141
context.getCoreLibrary().objectSpaceModule,
148142
"trace_allocation",

0 commit comments

Comments
 (0)