Skip to content

Commit acc97f5

Browse files
committed
[GR-18411] Update graal and address DynamicObject deprecations
PullRequest: truffleruby/3377
2 parents 84832be + 6473334 commit acc97f5

File tree

12 files changed

+165
-98
lines changed

12 files changed

+165
-98
lines changed

common.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"jdks": {
55
"openjdk11": {"name": "openjdk", "version": "11.0.11+9", "platformspecific": true },
66
"oraclejdk11": {"name": "oraclejdk", "version": "11.0.11+9", "platformspecific": true },
7-
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.15+6-jvmci-22.2-b02", "platformspecific": true },
8-
"labsjdk-ce-11-llvm": {"name": "labsjdk", "version": "ce-11.0.15+6-jvmci-22.2-b02-sulong", "platformspecific": true },
9-
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.16+6-jvmci-22.2-b02", "platformspecific": true },
10-
"labsjdk-ee-11-llvm": {"name": "labsjdk", "version": "ee-11.0.16+6-jvmci-22.2-b02-sulong", "platformspecific": true },
7+
"labsjdk-ce-11": {"name": "labsjdk", "version": "ce-11.0.16+5-jvmci-22.2-b03", "platformspecific": true },
8+
"labsjdk-ce-11-llvm": {"name": "labsjdk", "version": "ce-11.0.16+5-jvmci-22.2-b03-sulong", "platformspecific": true },
9+
"labsjdk-ee-11": {"name": "labsjdk", "version": "ee-11.0.16+9-jvmci-22.2-b03", "platformspecific": true },
10+
"labsjdk-ee-11-llvm": {"name": "labsjdk", "version": "ee-11.0.16+9-jvmci-22.2-b03-sulong", "platformspecific": true },
1111

1212
"oraclejdk17": {"name": "oraclejdk", "version": "17.0.1+12", "platformspecific": true },
13-
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.4+1-jvmci-22.2-b02", "platformspecific": true },
14-
"labsjdk-ce-17Debug": {"name": "labsjdk", "version": "ce-17.0.4+1-jvmci-22.2-b02-debug", "platformspecific": true },
15-
"labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.4+1-jvmci-22.2-b02-sulong", "platformspecific": true },
16-
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.4+6-jvmci-22.2-b02", "platformspecific": true },
17-
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.4+6-jvmci-22.2-b02-debug", "platformspecific": true },
18-
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.4+6-jvmci-22.2-b02-sulong", "platformspecific": true }
13+
"labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.4+5-jvmci-22.2-b03", "platformspecific": true },
14+
"labsjdk-ce-17Debug": {"name": "labsjdk", "version": "ce-17.0.4+5-jvmci-22.2-b03-debug", "platformspecific": true },
15+
"labsjdk-ce-17-llvm": {"name": "labsjdk", "version": "ce-17.0.4+5-jvmci-22.2-b03-sulong", "platformspecific": true },
16+
"labsjdk-ee-17": {"name": "labsjdk", "version": "ee-17.0.4+9-jvmci-22.2-b03", "platformspecific": true },
17+
"labsjdk-ee-17Debug": {"name": "labsjdk", "version": "ee-17.0.4+9-jvmci-22.2-b03-debug", "platformspecific": true },
18+
"labsjdk-ee-17-llvm": {"name": "labsjdk", "version": "ee-17.0.4+9-jvmci-22.2-b03-sulong", "platformspecific": true }
1919
},
2020

2121
"COMMENT.devkits" : "The devkits versions reflect those used to build the JVMCI JDKs (e.g., see devkit_platform_revisions in <jdk>/make/conf/jib-profiles.js)",

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "e760eb9b69bd02f93e2054dd30af3419b106e88c",
10+
"version": "2facc6db4becbea40867fa98c6248f66571d8a0a",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "e760eb9b69bd02f93e2054dd30af3419b106e88c",
19+
"version": "2facc6db4becbea40867fa98c6248f66571d8a0a",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

spec/truffle/interop/meta_object_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
require_relative '../../ruby/spec_helper'
1010

1111
describe "Truffle::Interop.meta_object" do
12-
1312
it "returns Integer class for an integer" do
1413
Truffle::Interop.meta_object(14).should == Integer
1514
end
@@ -30,4 +29,15 @@
3029
Truffle::Interop.meta_object([1, 2, 3]).should == Array
3130
end
3231

32+
it "returns a Ruby class implementing all meta objects methods" do
33+
meta = Truffle::Interop.meta_object("string")
34+
Truffle::Interop.meta_simple_name(meta).should == 'String'
35+
Truffle::Interop.meta_qualified_name(meta).should == 'String'
36+
Truffle::Interop.meta_parents(meta).to_a.should == [Object]
37+
38+
Truffle::Interop.meta_simple_name(Enumerator::Lazy).should == 'Lazy'
39+
Truffle::Interop.meta_qualified_name(Enumerator::Lazy).should == 'Enumerator::Lazy'
40+
41+
Truffle::Interop.should_not.has_meta_parents?(Enumerable)
42+
end
3343
end

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.oracle.truffle.api.frame.Frame;
2222
import com.oracle.truffle.api.interop.InteropLibrary;
2323
import com.oracle.truffle.api.interop.UnsupportedMessageException;
24+
import com.oracle.truffle.api.object.PropertyGetter;
2425
import com.oracle.truffle.api.utilities.AssumedValue;
2526
import org.truffleruby.RubyContext;
2627
import org.truffleruby.builtins.CoreMethod;
@@ -438,24 +439,22 @@ protected RubyClass getClass(Object self) {
438439
@GenerateUncached
439440
public abstract static class CopyInstanceVariablesNode extends RubyBaseNode {
440441

441-
public static final Property[] EMPTY_PROPERTY_ARRAY = new Property[0];
442+
public static final PropertyGetter[] EMPTY_PROPERTY_GETTER_ARRAY = new PropertyGetter[0];
442443

443444
public abstract RubyDynamicObject execute(RubyDynamicObject newObject, RubyDynamicObject from);
444445

445446
@ExplodeLoop
446447
@Specialization(
447-
guards = { "from.getShape() == cachedShape", "properties.length <= MAX_EXPLODE_SIZE" },
448+
guards = { "from.getShape() == cachedShape", "propertyGetters.length <= MAX_EXPLODE_SIZE" },
448449
limit = "getDynamicObjectCacheLimit()")
449450
protected RubyDynamicObject copyCached(RubyDynamicObject newObject, RubyDynamicObject from,
450451
@Cached("from.getShape()") Shape cachedShape,
451-
// GR-25595: should probably be shared between specialization instances but Truffle does not support it yet
452-
@Cached DispatchNode allocateNode,
453-
@Cached(value = "getCopiedProperties(cachedShape)", dimensions = 1) Property[] properties,
454-
@Cached("createWriteFieldNodes(properties)") DynamicObjectLibrary[] writeFieldNodes) {
455-
for (int i = 0; i < properties.length; i++) {
456-
final Property property = properties[i];
457-
final Object value = property.get(from, cachedShape);
458-
writeFieldNodes[i].putWithFlags(newObject, property.getKey(), value, property.getFlags());
452+
@Cached(value = "getCopiedProperties(cachedShape)", dimensions = 1) PropertyGetter[] propertyGetters,
453+
@Cached("createWriteFieldNodes(propertyGetters)") DynamicObjectLibrary[] writeFieldNodes) {
454+
for (int i = 0; i < propertyGetters.length; i++) {
455+
final PropertyGetter propertyGetter = propertyGetters[i];
456+
final Object value = propertyGetter.get(from);
457+
writeFieldNodes[i].putWithFlags(newObject, propertyGetter.getKey(), value, propertyGetter.getFlags());
459458
}
460459

461460
return newObject;
@@ -472,21 +471,21 @@ protected RubyDynamicObject copyUncached(RubyDynamicObject newObject, RubyDynami
472471
return newObject;
473472
}
474473

475-
protected Property[] getCopiedProperties(Shape shape) {
476-
final List<Property> copiedProperties = new ArrayList<>();
474+
protected PropertyGetter[] getCopiedProperties(Shape shape) {
475+
final List<PropertyGetter> copiedProperties = new ArrayList<>();
477476

478477
for (Property property : shape.getProperties()) {
479478
if (property.getKey() instanceof String) {
480-
copiedProperties.add(property);
479+
copiedProperties.add(Objects.requireNonNull(shape.makePropertyGetter(property.getKey())));
481480
}
482481
}
483482

484-
return copiedProperties.toArray(EMPTY_PROPERTY_ARRAY);
483+
return copiedProperties.toArray(EMPTY_PROPERTY_GETTER_ARRAY);
485484
}
486485

487-
protected DynamicObjectLibrary[] createWriteFieldNodes(Property[] properties) {
488-
final DynamicObjectLibrary[] nodes = new DynamicObjectLibrary[properties.length];
489-
for (int i = 0; i < properties.length; i++) {
486+
protected DynamicObjectLibrary[] createWriteFieldNodes(PropertyGetter[] propertyGetters) {
487+
final DynamicObjectLibrary[] nodes = new DynamicObjectLibrary[propertyGetters.length];
488+
for (int i = 0; i < propertyGetters.length; i++) {
490489
nodes[i] = DynamicObjectLibrary.getFactory().createDispatched(1);
491490
}
492491
return nodes;
@@ -496,12 +495,13 @@ protected DynamicObjectLibrary[] createWriteFieldNodes(Property[] properties) {
496495
private void copyInstanceVariables(RubyDynamicObject from, RubyDynamicObject to) {
497496
// Concurrency: OK if callers create the object and publish it after copy
498497
// Only copy user-level instance variables, hidden ones are initialized later with #initialize_copy.
499-
for (Property property : getCopiedProperties(from.getShape())) {
498+
Shape shape = from.getShape();
499+
for (PropertyGetter propertyGetter : getCopiedProperties(shape)) {
500500
DynamicObjectLibrary.getUncached().putWithFlags(
501501
to,
502-
property.getKey(),
503-
property.get(from, from.getShape()),
504-
property.getFlags());
502+
propertyGetter.getKey(),
503+
propertyGetter.get(from),
504+
propertyGetter.getFlags());
505505
}
506506
}
507507
}

src/main/java/org/truffleruby/core/klass/RubyClass.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
import java.util.Set;
1414

1515
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
16+
import com.oracle.truffle.api.interop.InteropLibrary;
17+
import com.oracle.truffle.api.library.ExportLibrary;
18+
import com.oracle.truffle.api.library.ExportMessage;
1619
import com.oracle.truffle.api.source.SourceSection;
1720
import org.truffleruby.RubyLanguage;
1821
import org.truffleruby.core.module.RubyModule;
22+
import org.truffleruby.debug.SingleElementArray;
1923
import org.truffleruby.language.RubyDynamicObject;
2024
import org.truffleruby.language.objects.ObjectGraph;
2125
import org.truffleruby.language.objects.ObjectGraphNode;
@@ -24,6 +28,7 @@
2428

2529
import static org.truffleruby.language.RubyBaseNode.nil;
2630

31+
@ExportLibrary(InteropLibrary.class)
2732
public final class RubyClass extends RubyModule implements ObjectGraphNode {
2833

2934
private static final RubyClass[] EMPTY_CLASS_ARRAY = new RubyClass[0];
@@ -118,4 +123,16 @@ public void getAdjacentObjects(Set<Object> reachable) {
118123
ObjectGraph.addProperty(reachable, superclass);
119124
}
120125

126+
// region MetaObject
127+
@ExportMessage
128+
public boolean hasMetaParents() {
129+
return true;
130+
}
131+
132+
@ExportMessage
133+
public Object getMetaParents() {
134+
return new SingleElementArray(superclass);
135+
}
136+
// endregion
137+
121138
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 2.0, or
7+
* GNU General Public License version 2, or
8+
* GNU Lesser General Public License version 2.1.
9+
*/
10+
package org.truffleruby.debug;
11+
12+
import com.oracle.truffle.api.dsl.Cached;
13+
import com.oracle.truffle.api.interop.InteropLibrary;
14+
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
15+
import com.oracle.truffle.api.interop.TruffleObject;
16+
import com.oracle.truffle.api.library.ExportLibrary;
17+
import com.oracle.truffle.api.library.ExportMessage;
18+
import com.oracle.truffle.api.profiles.BranchProfile;
19+
20+
@ExportLibrary(InteropLibrary.class)
21+
public class SingleElementArray implements TruffleObject {
22+
23+
private final Object element;
24+
25+
public SingleElementArray(Object element) {
26+
this.element = element;
27+
}
28+
29+
@ExportMessage
30+
protected boolean hasArrayElements() {
31+
return true;
32+
}
33+
34+
@ExportMessage
35+
protected long getArraySize() {
36+
return 1;
37+
}
38+
39+
@ExportMessage
40+
protected Object readArrayElement(long index,
41+
@Cached BranchProfile errorProfile) throws InvalidArrayIndexException {
42+
if (isArrayElementReadable(index)) {
43+
return element;
44+
} else {
45+
errorProfile.enter();
46+
throw InvalidArrayIndexException.create(index);
47+
}
48+
}
49+
50+
@ExportMessage
51+
protected boolean isArrayElementReadable(long index) {
52+
return index == 0;
53+
}
54+
55+
}

src/main/java/org/truffleruby/interop/InteropNodes.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,29 @@ protected Object getMetaQualifiedName(Object metaObject,
19971997
}
19981998
}
19991999
}
2000+
2001+
@CoreMethod(names = "has_meta_parents?", onSingleton = true, required = 1)
2002+
public abstract static class HasMetaParentsNode extends CoreMethodArrayArgumentsNode {
2003+
@Specialization(limit = "getInteropCacheLimit()")
2004+
protected boolean hasMetaParents(Object receiver,
2005+
@CachedLibrary("receiver") InteropLibrary interop) {
2006+
return interop.hasMetaParents(receiver);
2007+
}
2008+
}
2009+
2010+
@CoreMethod(names = "meta_parents", onSingleton = true, required = 1)
2011+
public abstract static class GetMetaParentsNode extends CoreMethodArrayArgumentsNode {
2012+
@Specialization(limit = "getInteropCacheLimit()")
2013+
protected Object getMetaParents(Object value,
2014+
@CachedLibrary("value") InteropLibrary interop,
2015+
@Cached TranslateInteropExceptionNode translateInteropException) {
2016+
try {
2017+
return interop.getMetaParents(value);
2018+
} catch (UnsupportedMessageException e) {
2019+
throw translateInteropException.execute(e);
2020+
}
2021+
}
2022+
}
20002023
// endregion
20012024

20022025
// region Hash entries

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Set;
1818

1919
import com.oracle.truffle.api.frame.FrameDescriptor;
20+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
2021
import org.truffleruby.RubyContext;
2122
import org.truffleruby.RubyLanguage;
2223
import org.truffleruby.core.proc.RubyProc;
@@ -138,7 +139,7 @@ public static Set<Object> getAdjacentObjects(RubyDynamicObject object) {
138139
}
139140

140141
for (Property property : object.getShape().getPropertyListInternal(false)) {
141-
final Object value = property.get(object, object.getShape());
142+
final Object value = DynamicObjectLibrary.getUncached().getOrDefault(object, property.getKey(), null);
142143
addProperty(reachable, value);
143144
}
144145

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
*/
1010
package org.truffleruby.language.objects;
1111

12-
import com.oracle.truffle.api.object.ObjectType;
13-
14-
public final class RubyObjectType extends ObjectType {
15-
12+
public final class RubyObjectType {
1613
public RubyObjectType() {
1714
}
18-
1915
}

src/main/java/org/truffleruby/language/objects/shared/ReadAndShareFieldNode.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)