Skip to content

Commit faa584a

Browse files
committed
[GR-18411] Update graal import and adopt new APIs
PullRequest: truffleruby/3475
2 parents 5828b8a + 091f3a4 commit faa584a

File tree

28 files changed

+143
-41
lines changed

28 files changed

+143
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ New features:
66
* Add `Java.add_to_classpath` method to add jar paths at runtime (#2693, @bjfish).
77
* Add support for Ruby 3.1's Hash shorthand/punning syntax (@nirvdrum).
88
* Add support for Ruby 3.1's anonymous block forwarding syntax (@nirvdrum).
9+
* Added the following keyword arguments to `Polyglot::InnerContext.new`: `languages, language_options, inherit_all_access, code_sharing` (@eregon).
910

1011
Bug fixes:
1112

common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
"devkits": {
3131
"windows-jdk11": { "packages" : { "devkit:VS2017-15.9.24+1" : "==0" }},
3232
"windows-jdk17": { "packages" : { "devkit:VS2019-16.9.3+1" : "==0" }},
33+
"windows-jdk19": { "packages" : { "devkit:VS2022-17.1.0+1" : "==0" }},
3334
"linux-jdk11": { "packages" : { "devkit:gcc7.3.0-OEL6.4+1" : "==1" }},
34-
"linux-jdk17": { "packages" : { "devkit:gcc10.3.0-OL6.4+1" : "==0" }}
35+
"linux-jdk17": { "packages" : { "devkit:gcc10.3.0-OL6.4+1" : "==0" }},
36+
"linux-jdk19": { "packages" : { "devkit:gcc11.2.0-OL6.4+1" : "==0" }}
3537
},
3638

3739
"catch_files" : [

lib/mri/monitor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def mon_owned?
217217
def mon_synchronize(&block)
218218
Primitive.monitor_synchronize(@mon_mutex, block)
219219
end
220+
Truffle::Graal.always_split instance_method(:mon_synchronize)
220221
alias synchronize mon_synchronize
221222

222223
#

lib/truffle/truffle/cext.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
require_relative 'cext_constants'
1313
require_relative 'cext_structs'
1414

15+
# TODO (eregon, 1 Sep 2022): should we always_split or use separate CallTargets for usages of Primitive.call_with* in this file?
16+
1517
module Truffle::CExt
1618
DATA_TYPE = Primitive.object_hidden_var_create :data_type
1719
DATA_HOLDER = Primitive.object_hidden_var_create :data_holder
@@ -981,6 +983,7 @@ def rb_hash_foreach(hash, func, farg)
981983
end
982984
end
983985
end
986+
Truffle::Graal.always_split instance_method(:rb_hash_foreach)
984987

985988
def rb_path_to_class(path)
986989
begin
@@ -1049,6 +1052,7 @@ def rb_protect(function, arg, write_status, status)
10491052
Truffle::Interop.execute_without_conversion(write_status, status, pos)
10501053
res
10511054
end
1055+
Truffle::Graal.always_split instance_method(:rb_protect)
10521056

10531057
def rb_jump_tag(pos)
10541058
if pos > 0
@@ -1062,10 +1066,12 @@ def rb_jump_tag(pos)
10621066
def rb_yield(value)
10631067
Primitive.interop_execute(rb_block_proc, [value])
10641068
end
1069+
Truffle::Graal.always_split instance_method(:rb_yield)
10651070

10661071
def rb_yield_splat(values)
10671072
Primitive.interop_execute(rb_block_proc, values)
10681073
end
1074+
Truffle::Graal.always_split instance_method(:rb_yield_splat)
10691075

10701076
def rb_ivar_lookup(object, name, default_value)
10711077
# TODO CS 24-Jul-16 races - needs a new primitive or be defined in Java?
@@ -1394,6 +1400,7 @@ def rb_mutex_synchronize(mutex, func, arg)
13941400
Primitive.cext_unwrap(Primitive.interop_execute(func, [Primitive.cext_wrap(arg)]))
13951401
end
13961402
end
1403+
Truffle::Graal.always_split instance_method(:rb_mutex_synchronize)
13971404

13981405
def rb_gc_enable
13991406
GC.enable
@@ -1545,6 +1552,7 @@ def rb_ensure(b_proc, data1, e_proc, data2)
15451552
Primitive.interop_execute(e_proc, [data2])
15461553
end
15471554
end
1555+
Truffle::Graal.always_split instance_method(:rb_ensure)
15481556

15491557
def rb_rescue(b_proc, data1, r_proc, data2)
15501558
begin
@@ -1557,6 +1565,7 @@ def rb_rescue(b_proc, data1, r_proc, data2)
15571565
end
15581566
end
15591567
end
1568+
Truffle::Graal.always_split instance_method(:rb_rescue)
15601569

15611570
def rb_rescue2(b_proc, data1, r_proc, data2, rescued)
15621571
begin
@@ -1565,6 +1574,7 @@ def rb_rescue2(b_proc, data1, r_proc, data2, rescued)
15651574
Primitive.interop_execute(r_proc, [data2, Primitive.cext_wrap(e)])
15661575
end
15671576
end
1577+
Truffle::Graal.always_split instance_method(:rb_rescue2)
15681578

15691579
def rb_exec_recursive(func, obj, arg)
15701580
result = nil
@@ -1579,6 +1589,7 @@ def rb_exec_recursive(func, obj, arg)
15791589
result
15801590
end
15811591
end
1592+
Truffle::Graal.always_split instance_method(:rb_exec_recursive)
15821593

15831594
def rb_catch_obj(tag, func, data)
15841595
catch tag do |caught|

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": "f9726d7f20f5fce7b26578886a01e3750807d5d6",
10+
"version": "1fd25b8c637ea052ff7bea8dcbd5a779f5240833",
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": "f9726d7f20f5fce7b26578886a01e3750807d5d6",
19+
"version": "1fd25b8c637ea052ff7bea8dcbd5a779f5240833",
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/polyglot/inner_context_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
end
2424
end
2525

26+
it "can specify languages explicitly" do
27+
Polyglot::InnerContext.new(languages: ['ruby']) do |context|
28+
context.eval('ruby', '6 * 7').should == 42
29+
end
30+
end
31+
32+
it "can specify language options" do
33+
Polyglot::InnerContext.new(language_options: { 'ruby.debug' => 'true' }) do |context|
34+
context.eval('ruby', '$DEBUG').should == true
35+
end
36+
end
37+
38+
it "can specify whether to inherit access" do
39+
Polyglot::InnerContext.new(inherit_all_access: false, language_options: { 'ruby.core-load-path' => 'resource:/truffleruby' }) do |context|
40+
context.eval('ruby', 'Truffle::POSIX::NATIVE').should == false
41+
end
42+
end
43+
2644
it "treats Ruby objects from the inner context as foreign" do
2745
Polyglot::InnerContext.new do |context|
2846
obj = context.eval('ruby', "Object.new")

src/annotations/java/org/truffleruby/builtins/CoreMethod.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
* RubyHash, and the arguments descriptor will tell if it was kwargs or positional, as always. */
5252
boolean rest() default false;
5353

54+
/** Passes the optional block as an argument to the node. Also causes {@link Split#DEFAULT} to be resolved to
55+
* {@link Split#ALWAYS}, unless {@link #split()} is set to a non-default value, since if a block is passed and the
56+
* block is called it is necessary to split for the best performance. Splitting eagerly instead of lazily via the
57+
* heuristic avoids an extra copy and works better with {@code RubyRootNode#getParentFrameDescriptor()} when the
58+
* possible loop in this core method does many iterations on the first method call as it then preserves the
59+
* single-caller chain from the beginning, instead of breaking it until split and executed again for the first and
60+
* second call sites. {@link Split#NEVER} should be used if this method never calls the block but just stores it. */
5461
boolean needsBlock() default false;
5562

5663
/** Try to lower argument <code>i</code> (starting at 0) to an int if its value is a long. The 0 is reserved for
@@ -73,6 +80,6 @@
7380
/** Use these names in Ruby core methods stubs, ignore argument names in Java specializations. */
7481
String[] argumentNames() default {};
7582

76-
Split split() default Split.HEURISTIC;
83+
Split split() default Split.DEFAULT;
7784

7885
}

src/annotations/java/org/truffleruby/language/methods/Split.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
package org.truffleruby.language.methods;
1111

1212
public enum Split {
13+
/** Special value for the CoreMethod annotation, resolved to either HEURISTIC or ALWAYS, based on needsBlock */
14+
DEFAULT,
1315
ALWAYS,
1416
HEURISTIC,
1517
/** Disallow splitting for this CallTarget, which avoids making a eager uninitialized copy of the AST. Useful

src/main/java/org/truffleruby/builtins/CoreMethodNodeManager.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ private RubyClass getSingletonClass(Object object) {
121121
return SingletonClassNode.getUncached().executeSingletonClass(object);
122122
}
123123

124+
private Split effectiveSplit(Split split, boolean needsBlock) {
125+
if (context.getOptions().CORE_ALWAYS_CLONE) {
126+
return Split.ALWAYS;
127+
} else if (split == Split.DEFAULT) {
128+
return needsBlock ? Split.ALWAYS : Split.HEURISTIC;
129+
} else {
130+
return split;
131+
}
132+
}
133+
124134
private void addCoreMethod(RubyModule module, MethodDetails methodDetails) {
125135
final CoreMethod annotation = methodDetails.getMethodAnnotation();
126136

@@ -134,7 +144,7 @@ private void addCoreMethod(RubyModule module, MethodDetails methodDetails) {
134144
final NodeFactory<? extends RubyBaseNode> nodeFactory = methodDetails.getNodeFactory();
135145
final boolean onSingleton = annotation.onSingleton() || annotation.constructor();
136146
final boolean isModuleFunc = annotation.isModuleFunction();
137-
final Split split = context.getOptions().CORE_ALWAYS_CLONE ? Split.ALWAYS : annotation.split();
147+
final Split split = effectiveSplit(annotation.split(), annotation.needsBlock());
138148

139149
final Function<SharedMethodInfo, RootCallTarget> callTargetFactory = sharedMethodInfo -> {
140150
return createCoreMethodRootNode(nodeFactory, language, sharedMethodInfo, split, annotation);
@@ -164,6 +174,7 @@ public void addLazyCoreMethod(
164174
int required,
165175
int optional,
166176
boolean rest,
177+
boolean needsBlock,
167178
String... names) {
168179

169180
final RubyModule module = getModule(moduleName, isClass);
@@ -172,7 +183,7 @@ public void addLazyCoreMethod(
172183
if (alwaysInlined) {
173184
finalSplit = Split.NEVER;
174185
} else {
175-
finalSplit = context.getOptions().CORE_ALWAYS_CLONE ? Split.ALWAYS : split;
186+
finalSplit = effectiveSplit(split, needsBlock);
176187
}
177188

178189
final Function<SharedMethodInfo, RootCallTarget> callTargetFactory = sharedMethodInfo -> {
@@ -329,7 +340,7 @@ public RootCallTarget createCoreMethodRootNode(NodeFactory<? extends RubyBaseNod
329340

330341
if (method.lowerFixnum().length > 0 || method.raiseIfFrozenSelf() || method.raiseIfNotMutableSelf() ||
331342
method.returnsEnumeratorIfNoBlock() || !method.enumeratorSize().isEmpty() ||
332-
method.split() != Split.HEURISTIC) {
343+
method.split() != Split.DEFAULT) {
333344
throw new Error("Always-inlined methods do not support all @CoreMethod attributes for " + nodeClass);
334345
}
335346

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ protected RubyArray concatManyGeneral(RubyArray array, Object first, Object[] re
662662

663663
@CoreMethod(names = "delete", required = 1, needsBlock = true)
664664
@ImportStatic(ArrayGuards.class)
665-
@ReportPolymorphism
666665
public abstract static class DeleteNode extends YieldingCoreMethodNode {
667666

668667
@Child private SameOrEqualNode sameOrEqualNode = SameOrEqualNode.create();
@@ -823,7 +822,6 @@ protected Object deleteAtCopying(RubyArray array, int index,
823822

824823
@CoreMethod(names = "each", needsBlock = true, enumeratorSize = "size")
825824
@ImportStatic(ArrayGuards.class)
826-
@ReportPolymorphism
827825
public abstract static class EachNode extends YieldingCoreMethodNode implements ArrayElementConsumerNode {
828826

829827
@Specialization
@@ -841,7 +839,6 @@ public void accept(RubyArray array, RubyProc block, Object element, int index) {
841839

842840
@Primitive(name = "array_each_with_index")
843841
@ImportStatic(ArrayGuards.class)
844-
@ReportPolymorphism
845842
public abstract static class EachWithIndexNode extends PrimitiveArrayArgumentsNode
846843
implements ArrayElementConsumerNode {
847844

@@ -1007,7 +1004,6 @@ protected Object eqlNotArray(RubyArray a, Object b) {
10071004
}
10081005

10091006
@CoreMethod(names = "fill", rest = true, needsBlock = true, raiseIfFrozenSelf = true)
1010-
@ReportPolymorphism
10111007
public abstract static class FillNode extends ArrayCoreMethodNode {
10121008

10131009
@Specialization(
@@ -1333,21 +1329,18 @@ protected RubyArray initializeCopy(RubyArray self, RubyArray from,
13331329

13341330
@Primitive(name = "array_inject")
13351331
@ImportStatic(ArrayGuards.class)
1336-
@ReportPolymorphism
13371332
public abstract static class InjectNode extends YieldingCoreMethodNode {
13381333

13391334
@Child private DispatchNode dispatch = DispatchNode.create(PUBLIC);
13401335

13411336
// Uses block
13421337

13431338
@Specialization(guards = { "isEmptyArray(array)", "wasProvided(initialOrSymbol)" })
1344-
@ReportPolymorphism.Exclude
13451339
protected Object injectEmptyArray(RubyArray array, Object initialOrSymbol, NotProvided symbol, RubyProc block) {
13461340
return initialOrSymbol;
13471341
}
13481342

13491343
@Specialization(guards = { "isEmptyArray(array)" })
1350-
@ReportPolymorphism.Exclude
13511344
protected Object injectEmptyArrayNoInitial(
13521345
RubyArray array, NotProvided initialOrSymbol, NotProvided symbol, RubyProc block) {
13531346
return nil;
@@ -1486,7 +1479,6 @@ public Object injectSymbolHelper(VirtualFrame frame, RubyArray array, String sym
14861479

14871480
@CoreMethod(names = { "map", "collect" }, needsBlock = true, enumeratorSize = "size")
14881481
@ImportStatic(ArrayGuards.class)
1489-
@ReportPolymorphism
14901482
public abstract static class MapNode extends YieldingCoreMethodNode {
14911483

14921484
@Specialization(limit = "storageStrategyLimit()")
@@ -1759,7 +1751,6 @@ protected RubyArray pushMany(VirtualFrame frame, RubyArray array, Object value,
17591751

17601752
@CoreMethod(names = "reject", needsBlock = true, enumeratorSize = "size")
17611753
@ImportStatic(ArrayGuards.class)
1762-
@ReportPolymorphism
17631754
public abstract static class RejectNode extends YieldingCoreMethodNode {
17641755

17651756
@Specialization(limit = "storageStrategyLimit()")
@@ -1794,7 +1785,6 @@ protected Object reject(RubyArray array, RubyProc block,
17941785

17951786
@CoreMethod(names = "reject!", needsBlock = true, enumeratorSize = "size", raiseIfFrozenSelf = true)
17961787
@ImportStatic(ArrayGuards.class)
1797-
@ReportPolymorphism
17981788
public abstract static class RejectInPlaceNode extends YieldingCoreMethodNode {
17991789

18001790
@Child private BooleanCastNode booleanCastNode = BooleanCastNode.create();
@@ -2050,7 +2040,6 @@ private void reverse(ArrayStoreLibrary stores,
20502040

20512041
@CoreMethod(names = { "select", "filter" }, needsBlock = true, enumeratorSize = "size")
20522042
@ImportStatic(ArrayGuards.class)
2053-
@ReportPolymorphism
20542043
public abstract static class SelectNode extends YieldingCoreMethodNode {
20552044

20562045
@Specialization(limit = "storageStrategyLimit()")
@@ -2161,11 +2150,9 @@ protected int size(RubyArray array,
21612150

21622151
@CoreMethod(names = "sort", needsBlock = true)
21632152
@ImportStatic(ArrayGuards.class)
2164-
@ReportPolymorphism
21652153
public abstract static class SortNode extends ArrayCoreMethodNode {
21662154

21672155
@Specialization(guards = "isEmptyArray(array)")
2168-
@ReportPolymorphism.Exclude
21692156
protected RubyArray sortEmpty(RubyArray array, Object unusedBlock) {
21702157
return createEmptyArray();
21712158
}

0 commit comments

Comments
 (0)