Skip to content

Commit

Permalink
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions truffle/src/main/java/org/jruby/truffle/stdlib/ObjSpaceNodes.java
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@
*/
package org.jruby.truffle.stdlib;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
@@ -33,31 +34,6 @@ public MemsizeOfNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isNil(nil)")
public int memsizeOf(Object nil) {
return 0;
}

@Specialization
public int memsizeOf(boolean object) {
return 0;
}

@Specialization
public int memsizeOf(int object) {
return 0;
}

@Specialization
public int memsizeOf(long object) {
return 0;
}

@Specialization
public int memsizeOf(double object) {
return 0;
}

@Specialization(guards = "isRubyArray(object)")
public int memsizeOfArray(DynamicObject object) {
return 1 + object.getShape().getPropertyListInternal(false).size() + Layouts.ARRAY.getSize(object);
@@ -78,12 +54,22 @@ public int memsizeOfMatchData(DynamicObject object) {
return 1 + object.getShape().getPropertyListInternal(false).size() + Layouts.MATCH_DATA.getValues(object).length;
}

@Specialization(guards = {"!isNil(object)", "!isRubyArray(object)", "!isRubyHash(object)",
"!isRubyString(object)", "!isRubyMatchData(object)"})
@Specialization(guards = {
"!isNil(object)",
"!isRubyArray(object)",
"!isRubyHash(object)",
"!isRubyString(object)",
"!isRubyMatchData(object)"
})
public int memsizeOfObject(DynamicObject object) {
return 1 + object.getShape().getPropertyListInternal(false).size();
}

@Fallback

This comment has been minimized.

Copy link
@eregon

eregon Apr 9, 2016

Member

Fallback is usually inefficient, what about !isDynamicObject() there?

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Apr 9, 2016

Author Contributor

It's not inherently inefficient is it? It'll just be the negation of all other guards. And yeah in this case that's a lot and !isDynamicObject() would achieve the same thing more efficiently so I'll use that.

This comment has been minimized.

Copy link
@eregon

eregon Apr 9, 2016

Member

It is in the current implementation as long as the guards are not trivial, look at the generated code. The JavaDoc also warns about it.

This comment has been minimized.

Copy link
@eregon

eregon Apr 9, 2016

Member

On a side note, I also prefer the whitelist approach, even if slightly verbose as it would error if an unknown type (not primitive or DynamicObject) is passed.

public int memsize(Object object) {
return 0;
}

}

@CoreMethod(names = "adjacent_objects", isModuleFunction = true, required = 1)
@@ -93,7 +79,7 @@ public AdjacentObjectsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public DynamicObject adjacentObjects(DynamicObject object) {
final Set<DynamicObject> objects = ObjectGraph.getAdjacentObjects(object);
@@ -109,7 +95,7 @@ public RootObjectsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public DynamicObject rootObjects() {
final Set<DynamicObject> objects = ObjectGraph.stopAndGetRootObjects(this, getContext());
@@ -125,7 +111,7 @@ public TraceAllocationsStartNode(RubyContext context, SourceSection sourceSectio
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public DynamicObject traceAllocationsStart() {
getContext().getObjectSpaceManager().traceAllocationsStart();
@@ -141,7 +127,7 @@ public TraceAllocationsStopNode(RubyContext context, SourceSection sourceSection
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@TruffleBoundary
@Specialization
public DynamicObject traceAllocationsStop() {
getContext().getObjectSpaceManager().traceAllocationsStop();

0 comments on commit 4c7a3f5

Please sign in to comment.