Skip to content

Commit 7bdfdec

Browse files
committed
[GR-17457] Small inlining fixes.
PullRequest: truffleruby/2394
2 parents 9be9a1f + bc293be commit 7bdfdec

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public InternalMethod getMethod() {
331331

332332
@Override
333333
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
334-
if (args != null && args.length > 0) {
334+
if (args.length > 0) {
335335
throw new InlinedMethodNode.RewriteException();
336336
}
337337
return execute();
@@ -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.traceBsicObjectAllocation(instance, rubyClass, this);
639+
AllocationTracing.traceInlined(instance, "Class", "__allocate__", this);
640640
return instance;
641641
}
642642

src/main/java/org/truffleruby/core/inlined/InlinedMethodNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010
package org.truffleruby.core.inlined;
1111

12-
import com.oracle.truffle.api.exception.AbstractTruffleException;
1312
import com.oracle.truffle.api.frame.Frame;
13+
import com.oracle.truffle.api.nodes.ControlFlowException;
1414

1515
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1616
import org.truffleruby.language.methods.InternalMethod;
@@ -21,7 +21,7 @@ public abstract class InlinedMethodNode extends CoreMethodArrayArgumentsNode {
2121

2222
public abstract InternalMethod getMethod();
2323

24-
public static class RewriteException extends AbstractTruffleException {
24+
public static class RewriteException extends ControlFlowException {
2525

2626
private static final long serialVersionUID = -4128190563044417424L;
2727
}

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

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.truffleruby.RubyContext;
1414
import org.truffleruby.RubyLanguage;
1515
import org.truffleruby.core.inlined.InlinedDispatchNode;
16+
import org.truffleruby.core.inlined.InlinedMethodNode;
1617
import org.truffleruby.core.objectspace.ObjectSpaceManager;
1718
import org.truffleruby.core.string.RubyString;
1819
import org.truffleruby.core.string.StringOperations;
@@ -49,22 +50,41 @@ public static void trace(RubyLanguage language, RubyContext context, RubyDynamic
4950
}
5051

5152
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,
61+
InlinedMethodNode node) {
62+
final RubyLanguage language = node.getLanguage();
63+
final RubyContext context = node.getContext();
64+
65+
truffleTracing(language, instance);
66+
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);
72+
}
73+
}
74+
}
75+
76+
private static void truffleTracing(RubyLanguage language, Object instance) {
5277
CompilerAsserts.partialEvaluationConstant(language);
5378

5479
final AllocationReporter allocationReporter = language.getAllocationReporter();
5580
if (allocationReporter.isActive()) {
5681
allocationReporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
5782
allocationReporter.onReturnValue(instance, 0, AllocationReporter.SIZE_UNKNOWN);
5883
}
59-
60-
if (context.getObjectSpaceManager().isTracing(language)) {
61-
traceBoundary(language, context, instance, currentNode);
62-
}
6384
}
6485

6586
@TruffleBoundary
66-
private static void traceBoundary(RubyLanguage language, RubyContext context, Object object,
67-
Node currentNode) {
87+
private static void traceBoundary(RubyLanguage language, RubyContext context, Object object, Node currentNode) {
6888
final ObjectSpaceManager objectSpaceManager = context.getObjectSpaceManager();
6989
if (!objectSpaceManager.isTracingPaused()) {
7090
objectSpaceManager.setTracingPaused(true);
@@ -76,54 +96,20 @@ private static void traceBoundary(RubyLanguage language, RubyContext context, Ob
7696
}
7797
}
7898

79-
public static void traceBsicObjectAllocation(RubyDynamicObject instance, RubyDynamicObject rubyClass,
80-
RubyContextSourceNode node) {
81-
RubyLanguage language = node.getLanguage();
82-
RubyContext context = node.getContext();
83-
84-
if (!(node.getParent() instanceof InlinedDispatchNode)) {
85-
traceObject(language, context, instance, node);
86-
} else {
87-
CompilerAsserts.partialEvaluationConstant(language);
88-
89-
final AllocationReporter allocationReporter = language.getAllocationReporter();
90-
if (allocationReporter.isActive()) {
91-
allocationReporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
92-
allocationReporter.onReturnValue(instance, 0, AllocationReporter.SIZE_UNKNOWN);
93-
}
94-
95-
if (context.getObjectSpaceManager().isTracing(language)) {
96-
traceInlineBoundary(language, context, instance, rubyClass, node);
97-
}
98-
}
99-
}
100-
10199
@TruffleBoundary
102-
public static void traceInlineBoundary(RubyLanguage language, RubyContext context, RubyDynamicObject instance,
103-
RubyDynamicObject klass, RubyContextSourceNode node) {
100+
private static void traceInlineBoundary(RubyLanguage language, RubyContext context, RubyDynamicObject instance,
101+
String className, String allocatingMethod, RubyContextSourceNode node) {
104102
final ObjectSpaceManager objectSpaceManager = context.getObjectSpaceManager();
105103
if (!objectSpaceManager.isTracingPaused()) {
106104
objectSpaceManager.setTracingPaused(true);
107105
try {
108-
callTraceInlineAllocation(language, context, instance, klass, node);
106+
callTraceInlineAllocation(language, context, instance, className, allocatingMethod, node);
109107
} finally {
110108
objectSpaceManager.setTracingPaused(false);
111109
}
112110
}
113111
}
114112

115-
@TruffleBoundary
116-
public static void callTraceInlineAllocation(RubyLanguage language, RubyContext context, RubyDynamicObject instance,
117-
RubyDynamicObject klass, RubyContextSourceNode node) {
118-
final SourceSection allocatingSourceSection = context
119-
.getCallStack()
120-
.getTopMostUserSourceSection(node.getEncapsulatingSourceSection());
121-
final String className = LogicalClassNode.getUncached().execute(klass).fields
122-
.getName();
123-
124-
callAllocationTrace(language, context, instance, allocatingSourceSection, "__allocate__", className);
125-
}
126-
127113
@TruffleBoundary
128114
private static void callTraceAllocation(RubyLanguage language, RubyContext context, Object object,
129115
Node currentNode) {
@@ -135,14 +121,22 @@ private static void callTraceAllocation(RubyLanguage language, RubyContext conte
135121

136122
final Object allocatingSelf = RubyArguments.getSelf(allocatingFrame);
137123
final String allocatingMethod = RubyArguments.getMethod(allocatingFrame).getName();
138-
final String className = LogicalClassNode.getUncached().execute(allocatingSelf).fields
139-
.getName();
124+
final String className = LogicalClassNode.getUncached().execute(allocatingSelf).fields.getName();
125+
126+
callAllocationTrace(language, context, object, allocatingSourceSection, className, allocatingMethod);
127+
}
140128

141-
callAllocationTrace(language, context, object, allocatingSourceSection, allocatingMethod, className);
129+
@TruffleBoundary
130+
private static void callTraceInlineAllocation(RubyLanguage language, RubyContext context,
131+
RubyDynamicObject instance, String className, String allocatingMethod, RubyContextSourceNode node) {
132+
final SourceSection allocatingSourceSection = context
133+
.getCallStack()
134+
.getTopMostUserSourceSection(node.getEncapsulatingSourceSection());
135+
callAllocationTrace(language, context, instance, allocatingSourceSection, className, allocatingMethod);
142136
}
143137

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

0 commit comments

Comments
 (0)