Skip to content

Commit 72a48c8

Browse files
committed
Pass TestObjSpace#test_trace_object_allocations
* Trace allocations from StringLiteralNode. * Always use the top-most user SourceSection, which is correct and allows us to drop the boolean field of AllocateObjectNode. * Always use the current frame to get self and the class path.
1 parent 1d0ed29 commit 72a48c8

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

lib/truffle/objspace.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ def allocation_generation(object)
229229
def allocation_method_id(object)
230230
allocation = ALLOCATIONS[object]
231231
return nil if allocation.nil?
232-
allocation.method_id
232+
233+
method_id = allocation.method_id
234+
# The allocator function is hidden in MRI
235+
method_id = :new if method_id == :__allocate__
236+
method_id
233237
end
234238
module_function :allocation_method_id
235239

src/main/java/org/truffleruby/core/array/ArrayLiteralNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.truffleruby.core.CoreLibrary;
1818
import org.truffleruby.language.RubyNode;
1919
import org.truffleruby.language.objects.AllocateObjectNode;
20-
import org.truffleruby.language.objects.AllocateObjectNodeGen;
2120

2221
public abstract class ArrayLiteralNode extends RubyNode {
2322

@@ -54,7 +53,7 @@ protected DynamicObject makeGeneric(VirtualFrame frame, Object[] alreadyExecuted
5453
protected DynamicObject createArray(Object store, int size) {
5554
if (allocateObjectNode == null) {
5655
CompilerDirectives.transferToInterpreterAndInvalidate();
57-
allocateObjectNode = insert(AllocateObjectNodeGen.create(false));
56+
allocateObjectNode = insert(AllocateObjectNode.create());
5857
}
5958
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), store, size);
6059
}

src/main/java/org/truffleruby/core/objectspace/ObjectSpaceManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.oracle.truffle.api.Assumption;
4242
import com.oracle.truffle.api.CompilerDirectives;
4343
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
44-
import com.oracle.truffle.api.object.DynamicObject;
4544
import com.oracle.truffle.api.utilities.CyclicAssumption;
4645

4746
import org.truffleruby.RubyContext;

src/main/java/org/truffleruby/language/literal/StringLiteralNode.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020

2121
import com.oracle.truffle.api.frame.VirtualFrame;
2222
import com.oracle.truffle.api.object.DynamicObject;
23+
import org.truffleruby.Layouts;
2324
import org.truffleruby.core.rope.Rope;
24-
import org.truffleruby.core.string.StringOperations;
2525
import org.truffleruby.language.RubyNode;
26+
import org.truffleruby.language.objects.AllocateObjectNode;
2627

2728
public class StringLiteralNode extends RubyNode {
2829

30+
@Child AllocateObjectNode allocateNode = AllocateObjectNode.create();
31+
2932
private final Rope rope;
3033

3134
public StringLiteralNode(Rope rope) {
@@ -35,7 +38,7 @@ public StringLiteralNode(Rope rope) {
3538

3639
@Override
3740
public DynamicObject execute(VirtualFrame frame) {
38-
return StringOperations.createString(getContext(), rope);
41+
return allocateNode.allocate(coreLibrary().getStringClass(), Layouts.STRING.build(false, false, rope));
3942
}
4043

4144
}

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.jcodings.specific.UTF8Encoding;
2525
import org.truffleruby.Layouts;
2626
import org.truffleruby.core.objectspace.ObjectSpaceManager;
27-
import org.truffleruby.core.string.StringNodes;
2827
import org.truffleruby.core.string.StringOperations;
2928
import org.truffleruby.language.RubyBaseNode;
3029
import org.truffleruby.language.arguments.RubyArguments;
@@ -34,13 +33,7 @@
3433
public abstract class AllocateObjectNode extends RubyBaseNode {
3534

3635
public static AllocateObjectNode create() {
37-
return AllocateObjectNodeGen.create(true);
38-
}
39-
40-
private final boolean useCallerFrameForTracing;
41-
42-
public AllocateObjectNode(boolean useCallerFrameForTracing) {
43-
this.useCallerFrameForTracing = useCallerFrameForTracing;
36+
return AllocateObjectNodeGen.create();
4437
}
4538

4639
public DynamicObject allocate(DynamicObject classToAllocate, Object... values) {
@@ -100,17 +93,9 @@ public DynamicObject allocateTracing(DynamicObject classToAllocate, Object[] val
10093

10194
@CompilerDirectives.TruffleBoundary
10295
private void callTraceAllocation(DynamicObject object) {
103-
final FrameInstance allocatingFrameInstance;
104-
final SourceSection allocatingSourceSection;
105-
106-
if (useCallerFrameForTracing) {
107-
allocatingFrameInstance = getContext().getCallStack().getCallerFrameIgnoringSend();
108-
allocatingSourceSection = getContext().getCallStack().getTopMostUserSourceSection();
109-
} else {
110-
allocatingFrameInstance = Truffle.getRuntime().getCurrentFrame();
111-
allocatingSourceSection = getEncapsulatingSourceSection();
112-
}
96+
final SourceSection allocatingSourceSection = getContext().getCallStack().getTopMostUserSourceSection(getEncapsulatingSourceSection());
11397

98+
final FrameInstance allocatingFrameInstance = Truffle.getRuntime().getCurrentFrame();
11499
final Frame allocatingFrame = allocatingFrameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY);
115100

116101
final Object allocatingSelf = RubyArguments.getSelf(allocatingFrame);

test/mri/excludes/TestObjSpace.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
exclude :test_memsize_of_iseq, "needs investigation"
1919
exclude :test_memsize_of_root_shared_string, "needs investigation"
2020
exclude :test_reachable_objects_size, "needs investigation"
21-
exclude :test_trace_object_allocations, "needs investigation"
2221
exclude :test_count_objects_size_with_wrong_type, "needs investigation"
2322
exclude :test_dump_addresses_match_dump_all_addresses, "needs investigation"
2423
exclude :test_dump_all_full, "needs investigation"

0 commit comments

Comments
 (0)