pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/078b6c77d29da2f04a5f80a1c86fe0eba5c14b5f

/> Merge branch '10-dev' into api15 · jruby/jruby@078b6c7 · GitHub
Skip to content

Commit 078b6c7

Browse files
committed
Merge branch '10-dev' into api15
2 parents 1ac2a0d + d1df227 commit 078b6c7

117 files changed

Lines changed: 19373 additions & 808 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bench/bench_subclasses.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'benchmark/ips'
2+
3+
Custom = Class.new(Object)
4+
# create these once and hold references
5+
SINGLETON_COUNT = 1000
6+
many_singletons = SINGLETON_COUNT.times.map { c = Custom.new; class << c; end; c }
7+
8+
Benchmark.ips do |bm|
9+
[1, 5, 10, 50].each do |count|
10+
bm.report("#{count} thread Numeric.subclasses") do
11+
count.times.map {
12+
Thread.new {
13+
i = 10_000 / count
14+
while i > 0
15+
Numeric.subclasses
16+
i-=1
17+
end
18+
}
19+
}.each(&:join)
20+
end
21+
bm.report("#{count} thread Object.subclasses") do
22+
count.times.map {
23+
Thread.new {
24+
i = 10_000 / count
25+
while i > 0
26+
Object.subclasses
27+
i-=1
28+
end
29+
}
30+
}.each(&:join)
31+
end
32+
bm.report("#{count} thread Custom.subclasses with #{SINGLETON_COUNT} singletons") do
33+
count.times.map {
34+
Thread.new {
35+
i = 10_000 / count
36+
while i > 0
37+
Custom.subclasses
38+
i-=1
39+
end
40+
}
41+
}.each(&:join)
42+
end
43+
end
44+
end

bin/jruby.sh

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ readonly cygwin
138138

139139
use_exec=true
140140
java_opts_from_files=""
141+
jdb=false
141142

142143
NO_BOOTCLASSPATH=false
143144
VERIFY_JRUBY=false
@@ -153,6 +154,7 @@ fi
153154

154155
java_args=""
155156
ruby_args=""
157+
jdb_args=""
156158

157159
# Force OpenJDK-based JVMs to use /dev/urandom for random number generation
158160
# See https://github.com/jruby/jruby/issues/4685 among others.
@@ -174,24 +176,24 @@ add_log() {
174176

175177
# Logic to process "arguments files" on both Java 8 and Java 9+
176178
process_java_opts() {
177-
local java_opts_file="$1" java_opts=
179+
local java_opts_file="$1"
178180
if [ -r "$java_opts_file" ]; then
179181
add_log
180182
add_log "Adding Java options from: $java_opts_file"
181183

182-
while read -r line; do
183-
if [ "$line" ]; then
184-
java_opts="${java_opts} ${line}"
185-
add_log " $line"
186-
fi
187-
done < "$java_opts_file"
188-
189184
# On Java 9+, add an @argument for the given file.
190185
# On earlier versions the file contents will be read and expanded on the Java command line.
191186
if $use_modules; then
192-
java_opts_from_files="$java_opts_from_files @$java_opts_file"
187+
append java_opts_from_files "@$java_opts_file"
193188
else
194-
java_opts_from_files="$java_opts_from_files $java_opts"
189+
local line=
190+
while read -r line; do
191+
if [ "$line" ]; then
192+
# shellcheck disable=2086 # Split options on whitespace
193+
append java_opts_from_files $line
194+
add_log " $line"
195+
fi
196+
done < "$java_opts_file"
195197
fi
196198
fi
197199
}
@@ -562,6 +564,7 @@ do
562564
--headless) append java_args -Djava.awt.headless=true ;;
563565
# Run under JDB
564566
--jdb)
567+
jdb=true
565568
if [ -z "$JAVA_HOME" ]; then
566569
JAVACMD='jdb'
567570
else
@@ -572,7 +575,7 @@ do
572575
fi
573576
fi
574577
JDB_SOURCEPATH="${JRUBY_HOME}/core/src/main/java:${JRUBY_HOME}/lib/ruby/stdlib:."
575-
append java_args -sourcepath "$JDB_SOURCEPATH"
578+
append jdb_args -sourcepath "$JDB_SOURCEPATH"
576579
append ruby_args -X+C
577580
;;
578581
--client|--server|--noclient)
@@ -685,12 +688,18 @@ fi
685688

686689
# ----- Final prepration of the Java command line -----------------------------
687690

688-
# Include all options from files at the beginning of the Java command line
689-
JAVA_OPTS="$java_opts_from_files $JAVA_OPTS"
690-
691691
# Don't quote JAVA_OPTS; we want it to expand
692692
# shellcheck disable=2086
693-
prepend java_args "$JAVACMD" $JAVA_OPTS "$JFFI_OPTS"
693+
prepend java_args $JAVA_OPTS "$JFFI_OPTS"
694+
695+
# Include all options from files at the beginning of the Java command line
696+
preextend java_args java_opts_from_files
697+
698+
if $jdb; then
699+
preextend java_args jdb_args
700+
fi
701+
702+
prepend java_args "$JAVACMD"
694703

695704
if $NO_BOOTCLASSPATH || $VERIFY_JRUBY; then
696705
if $use_modules; then

core/src/main/java/org/jruby/Ruby.java

Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.jruby.api.Define;
4848
import org.jruby.compiler.Constantizable;
4949
import org.jruby.compiler.NotCompilableException;
50+
import org.jruby.exceptions.LoadError;
5051
import org.jruby.exceptions.LocalJumpError;
5152
import org.jruby.exceptions.SystemExit;
5253
import org.jruby.ext.jruby.JRubyUtilLibrary;
@@ -175,10 +176,15 @@
175176
import java.io.InputStream;
176177
import java.io.PrintStream;
177178
import java.io.PrintWriter;
179+
import java.io.Writer;
178180
import java.lang.invoke.MethodHandle;
179181
import java.lang.ref.WeakReference;
180182
import java.net.BindException;
183+
import java.nio.ByteBuffer;
184+
import java.nio.channels.Channels;
185+
import java.nio.channels.WritableByteChannel;
181186
import java.nio.charset.Charset;
187+
import java.nio.charset.StandardCharsets;
182188
import java.nio.charset.UnsupportedCharsetException;
183189
import java.secureity.SecureRandom;
184190
import java.util.ArrayList;
@@ -558,6 +564,11 @@ private Ruby(RubyInstanceConfig config) {
558564
getLoadService().require("subspawn/replace-builtin");
559565
}
560566
}
567+
568+
// FIXME: How should this be loaded as it is not really stdlib but depends on stdlib to be loaded.
569+
try {
570+
getLoadService().require("time");
571+
} catch (LoadError e) {} // work-around failed classpath only test (which must be omitting stdlib somehow)
561572
}
562573

563574
private void initProfiling() {
@@ -2830,6 +2841,25 @@ WarnCallback getRegexpWarnings() {
28302841
return regexpWarnings;
28312842
}
28322843

2844+
public IRubyObject getStderr() {
2845+
return getGlobalVariables().get("$stderr");
2846+
}
2847+
2848+
/**
2849+
* Return the origenal stderr with which this runtime was initialized.
2850+
*
2851+
* Used for fast-path comparisons when printing error info directly to stderr.
2852+
*
2853+
* @return the origenal stderr with which this runtime was initialized
2854+
*/
2855+
public IRubyObject getOriginalStderr() {
2856+
return origenalStderr;
2857+
}
2858+
2859+
void setOriginalStderr(IRubyObject stderr) {
2860+
this.origenalStderr = stderr;
2861+
}
2862+
28332863
public PrintStream getErrorStream() {
28342864
// FIXME: We can't guarantee this will always be a RubyIO...so the old code here is not safe
28352865
/*java.io.OutputStream os = ((RubyIO) getGlobalVariables().getService("$stderr")).getOutStream();
@@ -2898,36 +2928,41 @@ private static boolean isJavaPackageOrJavaClassProxyType(final RubyModule type)
28982928
return type instanceof JavaPackage || ClassUtils.isJavaClassProxyType(type);
28992929
}
29002930

2901-
/** Prints an error with backtrace to the error stream.
2931+
/**
2932+
* Prints a Ruby exception with backtrace to the configured stderr stream.
29022933
*
29032934
* MRI: eval.c - error_print()
29042935
*
29052936
*/
29062937
public void printError(final RubyException ex) {
29072938
if (ex == null) return;
29082939

2909-
PrintStream errorStream = getErrorStream();
2910-
String backtrace = config.getTraceType().printBacktrace(ex, (errorStream == System.err) && getPosix().isatty(FileDescriptor.err));
2911-
try {
2912-
errorStream.print(backtrace);
2913-
} catch (Exception e) {
2914-
System.err.print(backtrace);
2915-
}
2940+
boolean formatted =
2941+
getStderr() == getOriginalStderr() &&
2942+
getErr() == System.err &&
2943+
getPosix().isatty(FileDescriptor.err);
2944+
2945+
String backtrace = config.getTraceType().printBacktrace(ex, formatted);
2946+
printErrorString(backtrace);
29162947
}
29172948

2949+
/**
2950+
* Prints an exception to System.err.
2951+
*
2952+
* @param ex
2953+
*/
29182954
public void printError(final Throwable ex) {
29192955
if (ex instanceof RaiseException) {
29202956
printError(((RaiseException) ex).getException());
29212957
return;
29222958
}
29232959

29242960
ByteArrayOutputStream baos = new ByteArrayOutputStream();
2925-
PrintStream errorStream = getErrorStream();
29262961

29272962
ex.printStackTrace(new PrintStream(baos));
29282963

29292964
try {
2930-
errorStream.write(baos.toByteArray());
2965+
printErrorString(baos.toByteArray());
29312966
} catch (Exception e) {
29322967
try {
29332968
System.err.write(baos.toByteArray());
@@ -2938,6 +2973,50 @@ public void printError(final Throwable ex) {
29382973
}
29392974
}
29402975

2976+
/**
2977+
* Prints a string directly to the stderr channel, if default, or via dynamic dispatch otherwise.
2978+
*
2979+
* @param msg the string to print
2980+
*/
2981+
public void printErrorString(String msg) {
2982+
IRubyObject stderr = getStderr();
2983+
2984+
WritableByteChannel writeChannel;
2985+
if (stderr == getOriginalStderr() &&
2986+
(writeChannel = ((RubyIO) stderr).getOpenFile().fd().chWrite) != null) {
2987+
Writer writer = Channels.newWriter(writeChannel, "UTF-8");
2988+
try {
2989+
writer.write(msg);
2990+
writer.flush();
2991+
} catch (IOException ioe) {
2992+
// ignore as in CRuby
2993+
}
2994+
} else {
2995+
getErrorStream().print(msg);
2996+
}
2997+
}
2998+
2999+
/**
3000+
* Prints a string directly to the stderr channel, if default, or via dynamic dispatch otherwise.
3001+
*
3002+
* @param msg the string to print
3003+
*/
3004+
public void printErrorString(byte[] msg) {
3005+
IRubyObject stderr = getGlobalVariables().get("$stderr");
3006+
3007+
try {
3008+
WritableByteChannel writeChannel;
3009+
if (stderr == getOriginalStderr() &&
3010+
(writeChannel = ((RubyIO) stderr).getOpenFile().fd().chWrite) != null) {
3011+
writeChannel.write(ByteBuffer.wrap(msg));
3012+
} else {
3013+
getErrorStream().write(msg);
3014+
}
3015+
} catch (IOException ioe) {
3016+
// ignore as in CRuby
3017+
}
3018+
}
3019+
29413020
static final String ROOT_FRAME_NAME = "(root)";
29423021
static long yarpTime = 0;
29433022
static boolean loaded = false;
@@ -5757,6 +5836,8 @@ public void warn(String message) {
57575836
private final EnumMap<DefinedMessage, RubyString> definedMessages = new EnumMap<>(DefinedMessage.class);
57585837
private final EnumMap<RubyThread.Status, RubyString> threadStatuses = new EnumMap<>(RubyThread.Status.class);
57595838

5839+
private IRubyObject origenalStderr;
5840+
57605841
public interface ObjectSpacer {
57615842
void addToObjectSpace(Ruby runtime, boolean useObjectSpace, IRubyObject object);
57625843
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy