Skip to content

Commit d48121d

Browse files
[GR-26970] Backports for 20.3
PullRequest: truffleruby/2096
2 parents 624569a + 8af5ae8 commit d48121d

File tree

15 files changed

+143
-85
lines changed

15 files changed

+143
-85
lines changed

.gitattributes

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# Merge options
2-
3-
/CHANGELOG.md merge=union
4-
51
# Rules for GitHub's Linguist language-classification system. We're abusing the
62
# 'vendored' attribute to exclude files as a lot of this isn't really vendored,
73
# and a whole lot of actually vendored code isn't listed! What we want to do is

3rd_party_licenses.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4141
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SU
4242
================================================================================
4343

44-
JONI 2.1.30
44+
JONI 2.1.40
4545

4646
/*
4747
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -365,7 +365,7 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
365365
SUCH DAMAGE.
366366
================================================================================
367367

368-
JCodings 1.0.45
368+
JCodings 1.0.55
369369

370370
/*
371371
* Permission is hereby granted, free of charge, to any person obtaining a copy

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ New features:
66
Bug fixes:
77

88
* Handle foreign null object as falsy value (#1902, @ssnickolay)
9-
* Fixed return value of `Enumerable#first` (#2056, @LillianZ).
9+
* Fixed return value of `Enumerable#first` with multiple yielded arguments (#2056, @LillianZ).
1010
* Improve reliability of the post install hook by disabling RubyGems (#2075).
1111
* Fixed top level exception handler to print exception cause (#2013).
1212
* Fixed issue when extending FFI from File (#2094).
@@ -15,8 +15,10 @@ Bug fixes:
1515
* Fixed issue with `spawn` when `:close` redirect is used (#2097).
1616
* Fixed `coverage` issue when `*eval` is used (#2078).
1717
* Use expanded load paths for feature matching (#1501).
18+
* Fixed handling of post arguments for `super()` (#2111).
1819
* Fixed `SystemStackError` sometimes replaced by an internal Java `NoClassDefFoundError` on JVM (#1743).
1920
* Fixed constant/identifier detection in lexer for non-ASCII encodings (#2079, #2102, @ivoanjo).
21+
* Fixed parsing of `--jvm` as an application argument (#2108).
2022

2123
Compatibility:
2224

@@ -49,6 +51,8 @@ Compatibility:
4951
* Convert objects with `#to_path` in `$LOAD_PATH` (#2119).
5052
* Handle the functions being native for `rb_thread_call_without_gvl()` (#2090).
5153
* Support refinements for Kernel#respond_to? (#2120, @ssnickolay)
54+
* JCodings has been updated from 1.0.45 to 1.0.55.
55+
* Joni has been updated from 2.1.30 to 2.1.40.
5256

5357
Performance:
5458

mx.truffleruby/suite.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@
5151
"maven": {
5252
"groupId": "org.jruby.joni",
5353
"artifactId": "joni",
54-
"version": "2.1.30"
54+
"version": "2.1.40"
5555
},
56-
"sha1": "a23a567521996c2a412688763892cddbca7c3bd6",
57-
"sourceSha1": "a1444342fc0c275613d43ca3d0a71ce919d85b18",
56+
"sha1": "18766fa1b624d615d3a1cac513bf729adfd6b38f",
57+
"sourceSha1": "85bb9546e4c63f00f02531eeab795685566baf7b",
5858
"license": ["MIT"],
5959
},
6060

6161
"JCODINGS": {
6262
"maven": {
6363
"groupId": "org.jruby.jcodings",
6464
"artifactId": "jcodings",
65-
"version": "1.0.45"
65+
"version": "1.0.55"
6666
},
67-
"sha1": "029404c013b3d51a8c60fac80409bb3d64dfb816",
68-
"sourceSha1": "702693ea01e006385f2834ad56dad54b7a4ca248",
67+
"sha1": "57169ef6964f44aef67b247cb87f053d93182488",
68+
"sourceSha1": "071891163f601416a5426d8f05b7d46139217ff1",
6969
"license": ["MIT"],
7070
},
7171
},

spec/tags/truffle/launcher_tags.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ slow:The launcher supports running rdoc symlinked
5656
slow:The launcher supports running ri symlinked
5757
slow:The launcher supports running ruby symlinked
5858
slow:The launcher supports running truffleruby symlinked
59+
arm64:The launcher for gem can install and uninstall the hello-world gem
5960
slow:The launcher should recognize ruby --vm options in RUBYOPT
6061
slow:The launcher should recognize ruby --vm options in TRUFFLERUBYOPT
61-
arm64:The launcher for gem can install and uninstall the hello-world gem
62+
slow:The launcher runtime configuration flags should recognize ruby --vm options in RUBYOPT when switching to JVM
63+
slow:The launcher runtime configuration flags should recognize ruby --vm options in TRUFFLERUBYOPT when switching to JVM
64+
slow:The launcher runtime configuration flags uses --native by default
65+
slow:The launcher runtime configuration flags switches to JVM with --jvm as a Ruby argument
66+
slow:The launcher runtime configuration flags keeps --jvm as an application argument if given as an application argument

spec/truffle/fixtures/argv.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
p ARGV

spec/truffle/launcher_spec.rb

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,6 @@ def check_status_or_print(stdout_and_stderr)
145145
end
146146
end
147147

148-
['RUBYOPT', 'TRUFFLERUBYOPT'].each do |var|
149-
it "should recognize ruby --vm options in #{var}" do
150-
out = ruby_exe('print Truffle::System.get_java_property("foo")', env: { var => "--vm.Dfoo=bar" }, args: @redirect)
151-
check_status_and_empty_stderr
152-
out.should == 'bar'
153-
end
154-
end
155-
156148
def should_print_full_java_command(options, env: {})
157149
out = ruby_exe(nil, options: options, env: env, args: @redirect)
158150
check_status_and_empty_stderr
@@ -410,4 +402,60 @@ def should_print_full_java_command(options, env: {})
410402
end
411403
end
412404

405+
['RUBYOPT', 'TRUFFLERUBYOPT'].each do |var|
406+
it "should recognize ruby --vm options in #{var}" do
407+
out = ruby_exe('print Truffle::System.get_java_property("foo")', env: { var => "--vm.Dfoo=bar" }, args: @redirect)
408+
check_status_and_empty_stderr
409+
out.should == 'bar'
410+
end
411+
end
412+
413+
guard -> {
414+
# GraalVM with both --jvm and --native
415+
TruffleRuby.graalvm_home and TruffleRuby.native?
416+
} do
417+
describe "runtime configuration flags" do
418+
before :each do
419+
@trufflerubyopt = ENV['TRUFFLERUBYOPT']
420+
# remove --native/--jvm from $TRUFFLERUBYOPT as they can conflict with command line arguments for these specs
421+
ENV['TRUFFLERUBYOPT'] = @trufflerubyopt.to_s.gsub(/--(native|jvm)\b/, '')
422+
end
423+
424+
after :each do
425+
ENV['TRUFFLERUBYOPT'] = @trufflerubyopt
426+
end
427+
428+
['RUBYOPT', 'TRUFFLERUBYOPT'].each do |var|
429+
it "should recognize ruby --vm options in #{var} when switching to JVM" do
430+
env = { var => "--jvm --vm.Dfoo=bar" }
431+
out = ruby_exe('puts RUBY_DESCRIPTION; puts Truffle::System.get_java_property("foo")', env: env, args: @redirect)
432+
check_status_and_empty_stderr
433+
out = out.lines.map(&:chomp)
434+
out[0].should =~ /GraalVM (CE|EE) JVM/
435+
out[1].should == 'bar'
436+
end
437+
end
438+
439+
it "uses --native by default" do
440+
out = ruby_exe(nil, options: "--version", args: @redirect)
441+
check_status_and_empty_stderr
442+
out.should =~ /GraalVM (CE|EE) Native/
443+
end
444+
445+
it "switches to JVM with --jvm as a Ruby argument" do
446+
out = ruby_exe(nil, options: "--jvm --version", args: @redirect)
447+
check_status_and_empty_stderr
448+
out.should =~ /GraalVM (CE|EE) JVM/
449+
end
450+
451+
it "keeps --jvm as an application argument if given as an application argument" do
452+
script = fixture(__FILE__, "argv.rb")
453+
out = ruby_exe(nil, options: "-v", args: "#{script} --jvm 1 2 #{@redirect}")
454+
check_status_and_empty_stderr
455+
out = out.lines.map(&:chomp)
456+
out[0].should =~ /GraalVM (CE|EE) Native/
457+
out.should.include?('["--jvm", "1", "2"]')
458+
end
459+
end
460+
end
413461
end

src/launcher/java/org/truffleruby/launcher/CommandLineOptions.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.io.File;
3333
import java.util.ArrayList;
34-
import java.util.Collections;
3534
import java.util.HashMap;
3635
import java.util.List;
3736
import java.util.Map;
@@ -58,26 +57,17 @@ public class CommandLineOptions {
5857
/** A thing to be executed: a file, inline script, etc. Used by executionAction when applicable. */
5958
String toExecute = "";
6059

61-
/** This should not be modified, as otherwise when exec()-ing to JVM from a native launcher, these options would be
62-
* passed on the command line, which fails if they are experimental. This would also cause parsing the options twice
63-
* with the current Launcher design. */
64-
private final Map<String, String> polyglotOptions;
6560
private final Map<String, String> options;
6661
private String[] arguments;
6762
private final List<String> unknownArguments;
6863
private Boolean gemOrBundle = null;
6964

70-
public CommandLineOptions(Map<String, String> polyglotOptions) {
71-
this.polyglotOptions = Collections.unmodifiableMap(polyglotOptions);
65+
public CommandLineOptions() {
7266
this.options = new HashMap<>();
7367
this.arguments = EMPTY_STRING_ARRAY;
7468
this.unknownArguments = new ArrayList<>();
7569
}
7670

77-
boolean isSetInPolyglotOptions(String optionName) {
78-
return polyglotOptions.containsKey(optionName);
79-
}
80-
8171
public Map<String, String> getOptions() {
8272
return options;
8373
}

src/launcher/java/org/truffleruby/launcher/CommandLineParser.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.util.HashMap;
4141
import java.util.List;
4242
import java.util.Map;
43-
import java.util.Objects;
4443
import java.util.function.BiConsumer;
4544
import java.util.logging.Handler;
4645
import java.util.logging.LogRecord;
@@ -56,25 +55,20 @@ public class CommandLineParser {
5655

5756
private final List<String> arguments;
5857
private int argumentIndex;
59-
private boolean processArgv;
58+
private final boolean processArgv;
6059
private final boolean rubyOpts;
6160
final CommandLineOptions config;
6261
private int lastInterpreterArgumentIndex;
6362
private int characterIndex;
6463

65-
public CommandLineParser(
66-
List<String> arguments,
67-
CommandLineOptions config,
68-
boolean processArgv,
69-
boolean rubyOpts) {
70-
64+
public CommandLineParser(List<String> arguments, CommandLineOptions config, boolean processArgv, boolean rubyOpts) {
7165
this.argumentIndex = 0;
7266
this.characterIndex = 0;
7367
this.lastInterpreterArgumentIndex = -1;
7468
this.config = config;
7569
this.processArgv = processArgv;
7670
this.rubyOpts = rubyOpts;
77-
this.arguments = Objects.requireNonNull(arguments);
71+
this.arguments = Collections.unmodifiableList(arguments);
7872
}
7973

8074
public void processArguments() throws CommandLineException {
@@ -102,19 +96,15 @@ public void processArguments() throws CommandLineException {
10296
}
10397
}
10498

105-
public int getLastInterpreterArgumentIndex() {
106-
return lastInterpreterArgumentIndex;
107-
}
108-
10999
private boolean endOfInterpreterArguments() {
110100
return lastInterpreterArgumentIndex != -1;
111101
}
112102

113103
private void processArgv() {
104+
boolean argvGlobalsOn = config.getOption(OptionsCatalog.ARGV_GLOBALS);
114105
ArrayList<String> arglist = new ArrayList<>();
115106
for (; argumentIndex < arguments.size(); argumentIndex++) {
116107
String arg = getCurrentArgument();
117-
boolean argvGlobalsOn = config.getOption(OptionsCatalog.ARGV_GLOBALS);
118108
if (argvGlobalsOn && arg.startsWith("-")) {
119109
arg = arg.substring(1);
120110
int split = arg.indexOf('=');

src/launcher/java/org/truffleruby/launcher/RubyLauncher.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ protected void printVersion() {
6161

6262
@Override
6363
protected List<String> preprocessArguments(List<String> args, Map<String, String> polyglotOptions) {
64-
config = new CommandLineOptions(polyglotOptions);
64+
// Set default options for the launcher which don't match the OptionKey's default.
65+
// These options can still be overridden if set explicitly.
66+
polyglotOptions.put(OptionsCatalog.EMBEDDED.getName(), "false");
67+
if (isAOT()) {
68+
final String launcher = ProcessProperties.getExecutableName();
69+
polyglotOptions.put(OptionsCatalog.LAUNCHER.getName(), launcher);
70+
}
71+
72+
config = new CommandLineOptions();
6573

6674
try {
6775
config.executionAction = ExecutionAction.UNSET;
@@ -70,26 +78,18 @@ protected List<String> preprocessArguments(List<String> args, Map<String, String
7078
argumentCommandLineParser.processArguments();
7179

7280
if (config.readRubyOptEnv) {
81+
/* Calling processArguments() here will also add any unrecognized arguments such as
82+
* --jvm/--native/--vm.* arguments and polyglot options to `config.getUnknownArguments()`, which will
83+
* then be processed by AbstractLanguageLauncher and Launcher. If we are going to run Native, Launcher
84+
* will apply VM options to the current process. If we are going to run on JVM, Launcher will collect
85+
* them and pass them when execve()'ing to bin/java. Polyglot options are parsed by
86+
* AbstractLanguageLauncher in the final process. */
7387
// Process RUBYOPT
7488
final List<String> rubyoptArgs = getArgsFromEnvVariable("RUBYOPT");
7589
new CommandLineParser(rubyoptArgs, config, false, true).processArguments();
7690
// Process TRUFFLERUBYOPT
7791
final List<String> trufflerubyoptArgs = getArgsFromEnvVariable("TRUFFLERUBYOPT");
7892
new CommandLineParser(trufflerubyoptArgs, config, false, false).processArguments();
79-
80-
if (isAOT()) {
81-
/* Append options from ENV variables to args after the last interpreter option, which makes sure
82-
* that maybeExec() processes the --vm.* options. These options are removed and are not passed to
83-
* the new process if exec() is being called as these options need to be passed when starting the
84-
* new VM process. The new process gets all arguments and options including those from ENV
85-
* variables. To avoid processing options from ENV variables twice, --disable-rubyopt is passed.
86-
* Only the native launcher can apply native and jvm options (it is too late for the running JVM to
87-
* apply --vm options), therefore this is not done on JVM. */
88-
final int index = argumentCommandLineParser.getLastInterpreterArgumentIndex();
89-
args.add(index, "--disable-rubyopt");
90-
args.addAll(index + 1, rubyoptArgs);
91-
args.addAll(index + 1 + rubyoptArgs.size(), trufflerubyoptArgs);
92-
}
9393
}
9494

9595
// Process RUBYLIB, must be after arguments and RUBYOPT
@@ -236,15 +236,6 @@ private int runRubyMain(Context.Builder contextBuilder, CommandLineOptions confi
236236
}
237237

238238
private Context createContext(Context.Builder builder, CommandLineOptions config) {
239-
if (isAOT() && !config.isSetInPolyglotOptions(OptionsCatalog.LAUNCHER.getName())) {
240-
final String launcher = ProcessProperties.getExecutableName();
241-
builder.option(OptionsCatalog.LAUNCHER.getName(), launcher);
242-
}
243-
244-
if (!config.isSetInPolyglotOptions(OptionsCatalog.EMBEDDED.getName())) {
245-
builder.option(OptionsCatalog.EMBEDDED.getName(), "false");
246-
}
247-
248239
if (config.isGemOrBundle() && getImplementationNameFromEngine().contains("Graal")) {
249240
// Apply options to run gem/bundle more efficiently
250241
builder.option("engine.Mode", "latency");

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ protected Object setTruffleWorkingDir(RubyString dir) {
146146
}
147147
}
148148

149+
@Primitive(name = "working_directory")
150+
public abstract static class GetTruffleWorkingDirNode extends PrimitiveArrayArgumentsNode {
151+
@Specialization
152+
protected RubyString getTruffleWorkingDir(
153+
@Cached StringNodes.MakeStringNode makeStringNode) {
154+
final String cwd = getContext().getFeatureLoader().getWorkingDirectory();
155+
final Encoding externalEncoding = getContext().getEncodingManager().getDefaultExternalEncoding();
156+
return makeStringNode.executeMake(cwd, externalEncoding, CodeRange.CR_UNKNOWN);
157+
}
158+
}
159+
149160
@CoreMethod(names = "get_java_property", onSingleton = true, required = 1)
150161
public abstract static class GetJavaPropertyNode extends CoreMethodArrayArgumentsNode {
151162

src/main/java/org/truffleruby/language/RubyContextNode.java

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

12+
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1213
import org.truffleruby.RubyContext;
1314
import org.truffleruby.RubyLanguage;
1415

@@ -18,18 +19,15 @@
1819
/** Has context but nothing else. */
1920
public abstract class RubyContextNode extends RubyBaseNode implements RubyNode.WithContext {
2021

21-
@CompilationFinal private RubyContext context;
22-
23-
// Accessors
22+
@CompilationFinal private ContextReference<RubyContext> contextReference;
2423

2524
@Override
2625
public RubyContext getContext() {
27-
if (context == null) {
26+
if (contextReference == null) {
2827
CompilerDirectives.transferToInterpreterAndInvalidate();
29-
context = RubyLanguage.getCurrentContext();
28+
contextReference = lookupContextReference(RubyLanguage.class);
3029
}
3130

32-
return context;
31+
return contextReference.get();
3332
}
34-
3533
}

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void setWorkingDirectory(String cwd) {
170170
this.cwd = cwd;
171171
}
172172

173+
@TruffleBoundary
173174
public String getWorkingDirectory() {
174175
if (cwd != null) {
175176
return cwd;

0 commit comments

Comments
 (0)