Skip to content

Commit 1c26c8f

Browse files
committed
Fix DynamicObject.define() deprecations
1 parent 8748994 commit 1c26c8f

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.concurrent.ConcurrentHashMap;
2424
import java.util.concurrent.ConcurrentMap;
2525

26+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
2627
import org.jcodings.specific.USASCIIEncoding;
2728
import org.jcodings.transcode.EConvFlags;
2829
import org.truffleruby.Layouts;
@@ -515,8 +516,8 @@ public CoreLibrary(RubyContext context) {
515516
symbolClass = defineClass("Symbol");
516517

517518
threadClass = defineClass("Thread");
518-
threadClass.define("@report_on_exception", true);
519-
threadClass.define("@abort_on_exception", false);
519+
DynamicObjectLibrary.getUncached().put(threadClass, "@report_on_exception", true);
520+
DynamicObjectLibrary.getUncached().put(threadClass, "@abort_on_exception", false);
520521
threadFactory = Layouts.THREAD.createThreadShape(threadClass, threadClass);
521522
Layouts.CLASS.setInstanceFactoryUnsafe(threadClass, threadFactory);
522523

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.oracle.truffle.api.interop.UnsupportedTypeException;
4040
import com.oracle.truffle.api.nodes.Node;
4141
import com.oracle.truffle.api.object.DynamicObject;
42+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
4243
import com.oracle.truffle.api.source.SourceSection;
4344

4445
public class CoreExceptions {
@@ -853,7 +854,8 @@ public DynamicObject loadError(String message, String path, Node currentNode) {
853854
// This is a workaround for the rubygems/security.rb file expecting the error path to be openssl
854855
path = "openssl";
855856
}
856-
loadError.define(
857+
DynamicObjectLibrary.getUncached().put(
858+
loadError,
857859
"@path",
858860
StringOperations.createString(context, StringOperations.encodeRope(path, UTF8Encoding.INSTANCE)));
859861
return loadError;
@@ -1142,7 +1144,7 @@ public DynamicObject systemExit(int exitStatus, Node currentNode) {
11421144
DynamicObject exceptionClass = context.getCoreLibrary().systemExitClass;
11431145
final DynamicObject systemExit = ExceptionOperations
11441146
.createRubyException(context, exceptionClass, message, currentNode, null);
1145-
systemExit.define("@status", exitStatus);
1147+
DynamicObjectLibrary.getUncached().put(systemExit, "@status", exitStatus);
11461148
return systemExit;
11471149
}
11481150

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
import com.oracle.truffle.api.nodes.IndirectCallNode;
143143
import com.oracle.truffle.api.nodes.Node;
144144
import com.oracle.truffle.api.object.DynamicObject;
145+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
145146
import com.oracle.truffle.api.object.Property;
146147
import com.oracle.truffle.api.object.Shape;
147148
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -496,7 +497,11 @@ private void copyInstanceVariables(DynamicObject from, DynamicObject to) {
496497
// Concurrency: OK if callers create the object and publish it after copy
497498
// Only copy user-level instance variables, hidden ones are initialized later with #initialize_copy.
498499
for (Property property : getCopiedProperties(from.getShape())) {
499-
to.define(property.getKey(), property.get(from, from.getShape()), property.getFlags());
500+
DynamicObjectLibrary.getUncached().putWithFlags(
501+
to,
502+
property.getKey(),
503+
property.get(from, from.getShape()),
504+
property.getFlags());
500505
}
501506
}
502507

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.math.BigInteger;
1919

2020
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
21+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
2122
import org.truffleruby.Layouts;
2223
import org.truffleruby.RubyContext;
2324
import org.truffleruby.cext.ValueWrapperManager;
@@ -135,10 +136,10 @@ public static long verySlowGetObjectID(RubyContext context, DynamicObject object
135136
if (SharedObjects.isShared(context, object)) {
136137
synchronized (object) {
137138
// no need for a write barrier here, objectID is a long.
138-
object.define(Layouts.OBJECT_ID_IDENTIFIER, objectID);
139+
DynamicObjectLibrary.getUncached().put(object, Layouts.OBJECT_ID_IDENTIFIER, objectID);
139140
}
140141
} else {
141-
object.define(Layouts.OBJECT_ID_IDENTIFIER, objectID);
142+
DynamicObjectLibrary.getUncached().put(object, Layouts.OBJECT_ID_IDENTIFIER, objectID);
142143
}
143144

144145
return objectID;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.language.objects;
1111

12+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1213
import org.truffleruby.RubyContext;
1314
import org.truffleruby.RubyLanguage;
1415
import org.truffleruby.language.RubyBaseNode;
@@ -54,10 +55,10 @@ protected Object ivarSetUncached(DynamicObject object, Object name, Object value
5455
if (SharedObjects.isShared(context, object)) {
5556
SharedObjects.writeBarrier(context, value);
5657
synchronized (object) {
57-
object.define(checkName(context, object, name, checkName), value);
58+
DynamicObjectLibrary.getUncached().put(object, checkName(context, object, name, checkName), value);
5859
}
5960
} else {
60-
object.define(checkName(context, object, name, checkName), value);
61+
DynamicObjectLibrary.getUncached().put(object, checkName(context, object, name, checkName), value);
6162
}
6263
return value;
6364
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.language.objects;
1111

12+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1213
import org.truffleruby.RubyContext;
1314
import org.truffleruby.RubyLanguage;
1415
import org.truffleruby.extra.ffi.Pointer;
@@ -162,7 +163,7 @@ protected void writeUncached(DynamicObject object, Object name, Object value, bo
162163
newShape.getProperty(name).setSafe(object, value, shape, newShape);
163164
}
164165
} else {
165-
object.define(name, value);
166+
DynamicObjectLibrary.getUncached().put(object, name, value);
166167
}
167168
}
168169

0 commit comments

Comments
 (0)