13
13
import org .truffleruby .RubyContext ;
14
14
import org .truffleruby .RubyLanguage ;
15
15
import org .truffleruby .core .inlined .InlinedDispatchNode ;
16
+ import org .truffleruby .core .inlined .InlinedMethodNode ;
16
17
import org .truffleruby .core .objectspace .ObjectSpaceManager ;
17
18
import org .truffleruby .core .string .RubyString ;
18
19
import org .truffleruby .core .string .StringOperations ;
@@ -49,22 +50,41 @@ public static void trace(RubyLanguage language, RubyContext context, RubyDynamic
49
50
}
50
51
51
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 ,
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 ) {
52
77
CompilerAsserts .partialEvaluationConstant (language );
53
78
54
79
final AllocationReporter allocationReporter = language .getAllocationReporter ();
55
80
if (allocationReporter .isActive ()) {
56
81
allocationReporter .onEnter (null , 0 , AllocationReporter .SIZE_UNKNOWN );
57
82
allocationReporter .onReturnValue (instance , 0 , AllocationReporter .SIZE_UNKNOWN );
58
83
}
59
-
60
- if (context .getObjectSpaceManager ().isTracing (language )) {
61
- traceBoundary (language , context , instance , currentNode );
62
- }
63
84
}
64
85
65
86
@ 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 ) {
68
88
final ObjectSpaceManager objectSpaceManager = context .getObjectSpaceManager ();
69
89
if (!objectSpaceManager .isTracingPaused ()) {
70
90
objectSpaceManager .setTracingPaused (true );
@@ -76,54 +96,20 @@ private static void traceBoundary(RubyLanguage language, RubyContext context, Ob
76
96
}
77
97
}
78
98
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
-
101
99
@ 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 ) {
104
102
final ObjectSpaceManager objectSpaceManager = context .getObjectSpaceManager ();
105
103
if (!objectSpaceManager .isTracingPaused ()) {
106
104
objectSpaceManager .setTracingPaused (true );
107
105
try {
108
- callTraceInlineAllocation (language , context , instance , klass , node );
106
+ callTraceInlineAllocation (language , context , instance , className , allocatingMethod , node );
109
107
} finally {
110
108
objectSpaceManager .setTracingPaused (false );
111
109
}
112
110
}
113
111
}
114
112
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
-
127
113
@ TruffleBoundary
128
114
private static void callTraceAllocation (RubyLanguage language , RubyContext context , Object object ,
129
115
Node currentNode ) {
@@ -135,14 +121,22 @@ private static void callTraceAllocation(RubyLanguage language, RubyContext conte
135
121
136
122
final Object allocatingSelf = RubyArguments .getSelf (allocatingFrame );
137
123
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
+ }
140
128
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 );
142
136
}
143
137
144
138
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 ) {
146
140
context .send (
147
141
context .getCoreLibrary ().objectSpaceModule ,
148
142
"trace_allocation" ,
0 commit comments