Skip to content

Commit e32e19d

Browse files
committed
Changes based on review.
1 parent b9fe51c commit e32e19d

File tree

6 files changed

+20
-35
lines changed

6 files changed

+20
-35
lines changed

src/main/java/org/truffleruby/cext/UnwrapNode.java

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

12-
import static org.truffleruby.cext.ValueWrapperManager.TAG_MASK;
1312
import static org.truffleruby.cext.ValueWrapperManager.TRUE_HANDLE;
1413
import static org.truffleruby.cext.ValueWrapperManager.UNDEF_HANDLE;
15-
import static org.truffleruby.cext.ValueWrapperManager.LONG_TAG;
1614
import static org.truffleruby.cext.ValueWrapperManager.NIL_HANDLE;
17-
import static org.truffleruby.cext.ValueWrapperManager.OBJECT_TAG;
1815
import static org.truffleruby.cext.ValueWrapperManager.FALSE_HANDLE;
1916

2017
import org.truffleruby.cext.UnwrapNodeGen.NativeToWrapperNodeGen;
@@ -35,7 +32,7 @@
3532
import com.oracle.truffle.api.object.DynamicObject;
3633
import com.oracle.truffle.api.profiles.BranchProfile;
3734

38-
@ImportStatic(Message.class)
35+
@ImportStatic({ Message.class, ValueWrapperManager.class })
3936
public abstract class UnwrapNode extends RubyBaseNode {
4037

4138
@ImportStatic(ValueWrapperManager.class)
@@ -73,14 +70,6 @@ public Object unwrapTaggedObject(long handle) {
7370
return getContext().getValueWrapperManager().getFromHandleMap(handle);
7471
}
7572

76-
public boolean isTaggedLong(long handle) {
77-
return (handle & LONG_TAG) == LONG_TAG;
78-
}
79-
80-
public boolean isTaggedObject(long handle) {
81-
return handle != FALSE_HANDLE && (handle & TAG_MASK) == OBJECT_TAG;
82-
}
83-
8473
public static UnwrapNativeNode create() {
8574
return UnwrapNativeNodeGen.create();
8675
}
@@ -121,20 +110,12 @@ public ValueWrapper unwrapTaggedObject(long handle) {
121110
return getContext().getValueWrapperManager().getWrapperFromHandleMap(handle);
122111
}
123112

124-
public boolean isTaggedLong(long handle) {
125-
return (handle & LONG_TAG) == LONG_TAG;
126-
}
127-
128-
public boolean isTaggedObject(long handle) {
129-
return handle != FALSE_HANDLE && (handle & TAG_MASK) == OBJECT_TAG;
130-
}
131-
132113
public static NativeToWrapperNode create() {
133114
return NativeToWrapperNodeGen.create();
134115
}
135116
}
136117

137-
@ImportStatic(Message.class)
118+
@ImportStatic({ Message.class, ValueWrapperManager.class })
138119
public static abstract class ToWrapperNode extends RubyBaseNode {
139120

140121
public abstract ValueWrapper execute(Object value);
@@ -166,10 +147,6 @@ public ValueWrapper unwrapTypeCastObject(TruffleObject value,
166147
}
167148
}
168149

169-
public static boolean isWrapper(TruffleObject value) {
170-
return value instanceof ValueWrapper;
171-
}
172-
173150
public static ToWrapperNode create() {
174151
return ToWrapperNodeGen.create();
175152
}
@@ -203,8 +180,4 @@ public Object unwrapTypeCastObject(TruffleObject value,
203180
throw new RaiseException(getContext(), coreExceptions().argumentError("Not a handle or a pointer", this));
204181
}
205182
}
206-
207-
public static boolean isWrapper(TruffleObject value) {
208-
return value instanceof ValueWrapper;
209-
}
210183
}

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import org.truffleruby.RubyContext;
1515
import org.truffleruby.collections.LongHashMap;
1616
import org.truffleruby.extra.ffi.Pointer;
17+
1718
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
19+
import com.oracle.truffle.api.interop.TruffleObject;
1820

1921
public class ValueWrapperManager {
2022

@@ -49,8 +51,7 @@ public ValueWrapperManager(RubyContext context) {
4951
* We keep a map of long wrappers that have been generated because various C extensions assume
5052
* that any given fixnum will translate to a given VALUE.
5153
*/
52-
@TruffleBoundary
53-
public synchronized ValueWrapper longWrapper(long value) {
54+
public ValueWrapper longWrapper(long value) {
5455
return new ValueWrapper(value, UNSET_HANDLE);
5556
}
5657

@@ -121,4 +122,16 @@ private Runnable createFinalizer(Pointer handle) {
121122
};
122123

123124
}
125+
126+
public static boolean isTaggedLong(long handle) {
127+
return (handle & LONG_TAG) == LONG_TAG;
128+
}
129+
130+
public static boolean isTaggedObject(long handle) {
131+
return handle != FALSE_HANDLE && (handle & TAG_MASK) == OBJECT_TAG;
132+
}
133+
134+
public static boolean isWrapper(TruffleObject value) {
135+
return value instanceof ValueWrapper;
136+
}
124137
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public abstract static class EachObjectNode extends YieldingCoreMethodNode {
110110
public int eachObject(NotProvided ofClass, DynamicObject block) {
111111
int count = 0;
112112

113-
getContext().getMarkingService().runMarkersAndDropKeptList();
114113
for (DynamicObject object : ObjectGraph.stopAndGetAllObjects(this, getContext())) {
115114
if (!isHidden(object)) {
116115
yield(block, object);
@@ -127,7 +126,6 @@ public int eachObject(DynamicObject ofClass, DynamicObject block,
127126
@Cached("create()") IsANode isANode) {
128127
int count = 0;
129128

130-
getContext().getMarkingService().runMarkersAndDropKeptList();
131129
for (DynamicObject object : ObjectGraph.stopAndGetAllObjects(this, getContext())) {
132130
if (!isHidden(object) && isANode.executeIsA(object, ofClass)) {
133131
yield(block, object);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static Set<DynamicObject> newRubyObjectSet() {
4040

4141
@TruffleBoundary
4242
public static Set<DynamicObject> stopAndGetAllObjects(Node currentNode, final RubyContext context) {
43+
context.getMarkingService().runMarkersAndDropKeptList();
4344
final Set<DynamicObject> visited = newRubyObjectSet();
4445

4546
final Thread initiatingJavaThread = Thread.currentThread();

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ public class OptionsCatalog {
618618
new String[]{});
619619
public static final IntegerOptionDescription CEXTS_MARKING_CACHE = new IntegerOptionDescription(
620620
"ruby.cexts.marking.cache",
621-
"Number of objects converted to native handles before the marker is run",
621+
"Number of objects converted to native handles before the marking service is run",
622622
null,
623623
100);
624624
public static final BooleanOptionDescription LOG_DYNAMIC_CONSTANT_LOOKUP = new BooleanOptionDescription(

tool/options.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ CEXTS: [cexts, boolean, true, Enable use of C extensions]
136136
CEXTS_LOG_LOAD: [cexts.log.load, boolean, false, Log loading of cexts]
137137
CEXTS_LOG_WARNINGS: [cexts.log.warnings, boolean, false, Log cexts warnings]
138138
CEXTS_LIBRARY_REMAP: [cexts.remap, string-array, [], 'Remap the name of native libraries, written in the form libexample.so:/path/to/actual/libexample.so']
139-
CEXTS_MARKING_CACHE: [cexts.marking.cache, integer, 100, 'Number of objects converted to native handles before the marker is run']
139+
CEXTS_MARKING_CACHE: [cexts.marking.cache, integer, 100, 'Number of objects converted to native handles before the marking service is run']
140140

141141
LOG_DYNAMIC_CONSTANT_LOOKUP: [constant.dynamic_lookup.log, boolean, false, Log source code positions where dynamic constant lookup is performed]
142142

0 commit comments

Comments
 (0)