Skip to content

Commit

Permalink
Showing 25 changed files with 312 additions and 251 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -1717,7 +1717,6 @@ private void initBuiltins() {
addLazyBuiltin("java.rb", "java", "org.jruby.javasupport.Java");
addLazyBuiltin("jruby.rb", "jruby", "org.jruby.ext.jruby.JRubyLibrary");
addLazyBuiltin("jruby/util.rb", "jruby/util", "org.jruby.ext.jruby.JRubyUtilLibrary");
addLazyBuiltin("jruby/type.rb", "jruby/type", "org.jruby.ext.jruby.JRubyTypeLibrary");
addLazyBuiltin("nkf.jar", "nkf", "org.jruby.ext.nkf.NKFLibrary");
addLazyBuiltin("stringio.jar", "stringio", "org.jruby.ext.stringio.StringIOLibrary");
addLazyBuiltin("strscan.jar", "strscan", "org.jruby.ext.strscan.StringScannerLibrary");
@@ -1741,7 +1740,7 @@ private void initBuiltins() {
addLazyBuiltin("pathname.jar", "pathname", "org.jruby.ext.pathname.PathnameLibrary");
addLazyBuiltin("set.rb", "set", "org.jruby.ext.set.SetLibrary");
addLazyBuiltin("date.jar", "date", "org.jruby.ext.date.DateLibrary");

addLazyBuiltin("securerandom.jar", "securerandom", "org.jruby.ext.securerandom.SecureRandomLibrary");
addLazyBuiltin("mathn/complex.jar", "mathn/complex", "org.jruby.ext.mathn.Complex");
addLazyBuiltin("mathn/rational.jar", "mathn/rational", "org.jruby.ext.mathn.Rational");
addLazyBuiltin("ripper.jar", "ripper", "org.jruby.ext.ripper.RipperLibrary");
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyLoadError.java
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ protected RubyLoadError(Ruby runtime, RubyClass exceptionClass) {

static RubyClass define(Ruby runtime, RubyClass exceptionClass) {
RubyClass LoadErrorClass = runtime.defineClass("LoadError", exceptionClass, (r, klass) -> new RubyLoadError(runtime, klass));

LoadErrorClass.addReadAttribute(runtime.getCurrentContext(), "path");
return LoadErrorClass;
}

136 changes: 68 additions & 68 deletions core/src/main/java/org/jruby/RubySignal.java
Original file line number Diff line number Diff line change
@@ -42,13 +42,13 @@

@JRubyModule(name="Signal")
public class RubySignal {
private final static SignalFacade SIGNALS = getSignalFacade();

private final static SignalFacade getSignalFacade() {
private final static SignalFacade SIGNAL_FACADE = initSignalFacade();

private final static SignalFacade initSignalFacade() {
try {
Class realFacadeClass = Class.forName("org.jruby.util.SunSignalFacade");
return (SignalFacade)realFacadeClass.newInstance();
} catch(Throwable e) {
return org.jruby.util.SunSignalFacade.class.newInstance();
} catch (Throwable e) {
return new NoFunctionalitySignalFacade();
}
}
@@ -72,24 +72,24 @@ public static void createSignal(Ruby runtime) {
}

public static Map<String, Integer> list() {
Map<String, Integer> signals = new HashMap<String, Integer>();
Map<String, Integer> signals = new HashMap<>();

for (Signal s : Signal.values()) {
if (!s.description().startsWith(SIGNAME_PREFIX))
continue;
if (!RUBY_18_SIGNALS.contains(signmWithoutPrefix(s.description())))
continue;
String desc = s.description();
if (!desc.startsWith(SIGNAME_PREFIX)) continue;

desc = signmWithoutPrefix(desc);
if (!SIGNAME(desc)) continue;

// replace CLD with CHLD value
int signo = s.intValue();
if (s == Signal.SIGCLD)
signo = Signal.SIGCHLD.intValue();

// omit unsupported signals
if (signo >= 20000)
continue;
if (signo >= 20000) continue;

signals.put(signmWithoutPrefix(s.description()), signo);
signals.put(desc, signo);
}

return signals;
@@ -119,22 +119,22 @@ public static IRubyObject list(ThreadContext context, IRubyObject recv) {

@JRubyMethod(required = 2, meta = true)
public static IRubyObject __jtrap_kernel(final IRubyObject recv, IRubyObject block, IRubyObject sig) {
return SIGNALS.trap(recv, block, sig);
return SIGNAL_FACADE.trap(recv, block, sig);
}

@JRubyMethod(required = 1, meta = true)
public static IRubyObject __jtrap_platform_kernel(final IRubyObject recv, IRubyObject sig) {
return SIGNALS.restorePlatformDefault(recv, sig);
return SIGNAL_FACADE.restorePlatformDefault(recv, sig);
}

@JRubyMethod(required = 1, meta = true)
public static IRubyObject __jtrap_osdefault_kernel(final IRubyObject recv, IRubyObject sig) {
return SIGNALS.restoreOSDefault(recv, sig);
return SIGNAL_FACADE.restoreOSDefault(recv, sig);
}

@JRubyMethod(required = 1, meta = true)
public static IRubyObject __jtrap_restore_kernel(final IRubyObject recv, IRubyObject sig) {
return SIGNALS.ignore(recv, sig);
return SIGNAL_FACADE.ignore(recv, sig);
}

@JRubyMethod(required = 1, meta = true)
@@ -177,58 +177,58 @@ public static String signmWithoutPrefix(String nm) {
return (nm.startsWith(SIGNAME_PREFIX)) ? nm.substring(SIGNAME_PREFIX.length()) : nm;
}

private static final Set<String> RUBY_18_SIGNALS;
static {
RUBY_18_SIGNALS = new HashSet<String>();
for (String name : new String[] {
"EXIT",
"HUP",
"INT",
"QUIT",
"ILL",
"TRAP",
"IOT",
"ABRT",
"EMT",
"FPE",
"KILL",
"BUS",
"SEGV",
"SYS",
"PIPE",
"ALRM",
"TERM",
"URG",
"STOP",
"TSTP",
"CONT",
"CHLD",
"CLD",
"TTIN",
"TTOU",
"IO",
"XCPU",
"XFSZ",
"VTALRM",
"PROF",
"WINCH",
"USR1",
"USR2",
"LOST",
"MSG",
"PWR",
"POLL",
"DANGER",
"MIGRATE",
"PRE",
"GRANT",
"RETRACT",
"SOUND",
"INFO",
}) {
RUBY_18_SIGNALS.add(name);
private static boolean SIGNAME(final String name) {
switch (name) {
case "EXIT":
case "HUP" :
case "INT" :
case "QUIT":
case "ILL" :
case "TRAP":
case "IOT" :
case "ABRT":
case "EMT" :
case "FPE" :
case "KILL":
case "BUS" :
case "SEGV":
case "SYS" :
case "PIPE":
case "ALRM":
case "TERM":
case "URG" :
case "STOP":
case "TSTP":
case "CONT":
case "CHLD":
case "CLD" :
case "TTIN":
case "TTOU":
case "IO" :
case "XCPU":
case "XFSZ":
case "PROF":
case "VTALRM":
case "WINCH":
case "USR1":
case "USR2":
case "LOST":
case "MSG" :
case "PWR" :
case "POLL":
case "DANGER":
case "MIGRATE":
case "PRE" :
case "GRANT":
case "RETRACT":
case "SOUND":
case "INFO":
return true;
default:
return false;
}
}

private static final String SIGNAME_PREFIX = "SIG";
}// RubySignal

}
38 changes: 23 additions & 15 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@
import org.jruby.exceptions.RaiseException;
import org.jruby.exceptions.ThreadKill;
import org.jruby.exceptions.Unrescuable;
import org.jruby.ext.thread.Mutex;
import org.jruby.internal.runtime.NativeThread;
import org.jruby.internal.runtime.RubyRunnable;
import org.jruby.internal.runtime.ThreadLike;
@@ -2154,6 +2155,28 @@ private String identityString() {
return "0x" + Integer.toHexString(System.identityHashCode(this));
}

private static final String MUTEX_FOR_THREAD_EXCLUSIVE = "MUTEX_FOR_THREAD_EXCLUSIVE";

@Deprecated // Thread.exclusive(&block)
@JRubyMethod(meta = true)
public static IRubyObject exclusive(ThreadContext context, IRubyObject recv, Block block) {
recv.callMethod(context, "warn", context.runtime.newString("Thread.exclusive is deprecated, use Thread::Mutex"));
return getMutexForThreadExclusive(context, (RubyClass) recv).synchronize(context, block);
}

private static Mutex getMutexForThreadExclusive(ThreadContext context, RubyClass recv) {
Mutex mutex = (Mutex) recv.getConstantNoConstMissing(MUTEX_FOR_THREAD_EXCLUSIVE, false, false);
if (mutex != null) return mutex;
synchronized (recv) {
mutex = (Mutex) recv.getConstantNoConstMissing(MUTEX_FOR_THREAD_EXCLUSIVE, false, false);
if (mutex == null) {
mutex = Mutex.newInstance(context, context.runtime.getThread().getClass("Mutex"), NULL_ARRAY, Block.NULL_BLOCK);
recv.setConstant(MUTEX_FOR_THREAD_EXCLUSIVE, mutex, true);
}
return mutex;
}
}

/**
* This is intended to be used to raise exceptions in Ruby threads from non-
* Ruby threads like Timeout's thread.
@@ -2183,21 +2206,6 @@ public boolean selectForAccept(RubyIO io) {
return select(io, SelectionKey.OP_ACCEPT);
}

@Deprecated // moved to ruby kernel
public static IRubyObject exclusive(ThreadContext context, IRubyObject recv, Block block) {
Ruby runtime = context.runtime;
ThreadService ts = runtime.getThreadService();
boolean critical = ts.getCritical();

ts.setCritical(true);

try {
return block.yieldSpecific(context);
} finally {
ts.setCritical(critical);
}
}

@Deprecated
public IRubyObject backtrace20(ThreadContext context, IRubyObject[] args) {
return backtrace(context);
12 changes: 7 additions & 5 deletions core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Original file line number Diff line number Diff line change
@@ -53,9 +53,11 @@
import java.io.ByteArrayInputStream;

/**
* Native part of require 'jruby'. Provides methods for swapping between the
* normal Ruby reference to an object and the Java-integration-wrapped
* reference.
* Native part of require 'jruby', e.g. provides methods for swapping between the normal Ruby reference to an
* object and the Java-integration-wrapped reference.
*
* Parts of JRuby name-space are loaded even without <code>require 'jruby'<code/>, those live under JRuby::Util.
* @see JRubyUtilLibrary
*/
@JRubyModule(name="JRuby")
public class JRubyLibrary implements Library {
@@ -194,7 +196,7 @@ public static IRubyObject identity_hash(ThreadContext context, IRubyObject recv,
return context.runtime.newFixnum(System.identityHashCode(obj));
}

@JRubyMethod(name = "set_last_exit_status", module = true) // used from JRuby::ProcessManager
@JRubyMethod(name = "set_last_exit_status", meta = true) // used from JRuby::ProcessManager
public static IRubyObject set_last_exit_status(ThreadContext context, IRubyObject recv,
IRubyObject status, IRubyObject pid) {
RubyProcess.RubyStatus processStatus = RubyProcess.RubyStatus.newProcessStatus(context.runtime,
@@ -298,7 +300,7 @@ public static IRubyObject compile(ThreadContext context, IRubyObject recv, IRuby
}, Block.NULL_BLOCK);
}

@JRubyMethod(module = true, visibility = Visibility.PRIVATE)
@Deprecated // @JRubyMethod(meta = true, visibility = Visibility.PRIVATE)
public static IRubyObject load_string_ext(ThreadContext context, IRubyObject recv) {
CoreExt.loadStringExtensions(context.runtime);
return context.nil;
143 changes: 120 additions & 23 deletions core/src/main/java/org/jruby/ext/jruby/JRubyUtilLibrary.java
Original file line number Diff line number Diff line change
@@ -31,18 +31,17 @@

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyBoolean;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyString;

import org.jruby.*;
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.exceptions.RaiseException;
import org.jruby.javasupport.Java;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.BasicLibraryService;
import org.jruby.runtime.load.Library;
import org.jruby.util.ClasspathLauncher;

@@ -56,12 +55,13 @@
*/
public class JRubyUtilLibrary implements Library {

// JRuby::Util no longer used by JRuby itself
public void load(Ruby runtime, boolean wrap) throws IOException {
RubyModule JRubyUtil = runtime.getOrCreateModule("JRuby").defineModuleUnder("Util");
RubyModule JRuby = runtime.getOrCreateModule("JRuby");
RubyModule JRubyUtil = JRuby.defineModuleUnder("Util");
JRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class);
JRubyUtil.setConstant("SEPARATOR", runtime.newString(org.jruby.util.cli.ArgumentProcessor.SEPARATOR));
JRubyUtil.setConstant("ON_WINDOWS", runtime.newBoolean(org.jruby.platform.Platform.IS_WINDOWS));
JRubyUtil.setConstant("ON_SOLARIS", runtime.newBoolean(org.jruby.platform.Platform.IS_SOLARIS));
}

@JRubyMethod(module = true)
@@ -87,23 +87,54 @@ public static IRubyObject setObjectSpaceEnabled(IRubyObject recv, IRubyObject ar
return runtime.newBoolean(enabled);
}

@JRubyMethod(name = "classloader_resources", module = true) // used from RGs' JRuby defaults
public static IRubyObject getClassLoaderResources(IRubyObject recv, IRubyObject arg) {
Ruby runtime = recv.getRuntime();
String resource = arg.convertToString().toString();
final List<RubyString> urlStrings = new ArrayList<>();
@JRubyMethod(meta = true, name = "native_posix?")
public static IRubyObject native_posix_p(ThreadContext context, IRubyObject self) {
return context.runtime.newBoolean(context.runtime.getPosix().isNative());
}

@Deprecated
public static IRubyObject getClassLoaderResources(IRubyObject recv, IRubyObject name) {
return class_loader_resources(recv.getRuntime().getCurrentContext(), recv, name);
}

/**
* @note class_loader_resources alias exists since 9.2
* @param context
* @param recv
* @param args (name, raw: false, path: false)
* @return an enumerable of class-loader resources
*/ // used from RGs' JRuby defaults (as well as jar_dependencies)
@JRubyMethod(module = true, name = "class_loader_resources", alias = "classloader_resources", required = 1, optional = 1)
public static IRubyObject class_loader_resources(ThreadContext context, IRubyObject recv, IRubyObject... args) {
final Ruby runtime = context.runtime;

final ClassLoader loader = runtime.getJRubyClassLoader();
final String name = args[0].convertToString().asJavaString();
final RubyArray resources = RubyArray.newArray(runtime);

boolean raw = false, path = false;
if (args.length > 1 && args[1] instanceof RubyHash) {
IRubyObject[] values = ArgsUtil.extractKeywordArgs(context, (RubyHash) args[1], "raw", "path");
raw = values[0] != null && values[0] != RubyBasicObject.UNDEF && values[0].isTrue();
path = values[1] != null && values[1] != RubyBasicObject.UNDEF && values[1].isTrue();
}

try {
Enumeration<URL> urls = runtime.getJRubyClassLoader().getResources(resource);
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
String urlString = getPath(url);
urlStrings.add(runtime.newString(urlString));
Enumeration<URL> e = loader.getResources(name);
while (e.hasMoreElements()) {
final URL entry = e.nextElement();
if (path) {
resources.append( RubyString.newString(runtime, getPath(entry)) );
} else if (raw) {
resources.append( Java.getInstance(runtime, entry) );
} else {
resources.append( RubyString.newString(runtime, entry.toString()) ); // toExternalForm
}
}
return RubyArray.newArray(runtime, urlStrings);
}
catch (IOException ignore) {
return runtime.newEmptyArray();
} catch (IOException ex) {
throw context.runtime.newIOErrorFromException(ex);
}
return resources;
}

@JRubyMethod(meta = true) // for RubyGems' JRuby defaults
@@ -125,6 +156,72 @@ public static IRubyObject extra_gem_paths(ThreadContext context, IRubyObject rec
return RubyArray.newArrayNoCopy(runtime, extra_gem_paths);
}

// used from jruby/kernel/proc.rb
@JRubyMethod(meta = true, name = "set_meta_class")
public static IRubyObject set_meta_class(ThreadContext context, IRubyObject recv, IRubyObject obj, IRubyObject klass) {
if (!(klass instanceof RubyClass)) {
klass = klass.getMetaClass();
}
((RubyObject) obj).setMetaClass((RubyClass) klass);
return context.nil;
}

/**
* Preffered way to boot-up JRuby extensions (available as <code>>JRuby.load_ext</code>).
* @param context
* @param recv
* @param klass
* @return loading outcome
*/
@JRubyMethod(module = true, name = { "load_ext" })
public static IRubyObject load_ext(ThreadContext context, IRubyObject recv, IRubyObject klass) {
if (klass instanceof RubySymbol) {
switch(((RubySymbol) klass).asJavaString()) {
case "string" : CoreExt.loadStringExtensions(context.runtime); return context.tru;
default : throw context.runtime.newArgumentError(':' + ((RubySymbol) klass).asJavaString());
}
}
return loadExtension(context.runtime, klass.convertToString().toString()) ? context.tru : context.fals;
}

private static boolean loadExtension(final Ruby runtime, final String className) {
Class<?> clazz = runtime.getJavaSupport().loadJavaClassQuiet(className);
// 1. BasicLibraryService interface
if (BasicLibraryService.class.isAssignableFrom(clazz)) {
try {
return ((BasicLibraryService) clazz.newInstance()).basicLoad(runtime);
} catch (ReflectiveOperationException e) {
final RaiseException ex = runtime.newNameError("cannot instantiate (ext) Java class " + className, className, e, true);
ex.initCause(e); throw ex;
} catch (Exception e) {
final RaiseException ex = runtime.newNameError("cannot load (ext) (" + className + ")", null, e, true);
ex.initCause(e); throw ex;
}
}
// 2 org.jruby.runtime.load.Library
if (Library.class.isAssignableFrom(clazz)) {
try {
((Library) clazz.newInstance()).load(runtime, false);
return true;
} catch (ReflectiveOperationException e) {
final RaiseException ex = runtime.newNameError("cannot instantiate (ext) Java class " + className, className, e, true);
ex.initCause(e); throw ex;
} catch (Exception e) {
final RaiseException ex = runtime.newNameError("cannot load (ext) (" + className + ")", null, e, true);
ex.initCause(e); throw ex;
}
}
// 3. public static void/boolean load(Ruby runtime) convention
try {
Object result = clazz.getMethod("load", Ruby.class).invoke(null, runtime);
return (result instanceof Boolean) && ! ((Boolean) result).booleanValue() ? false : true;
}
catch (Exception e) {
final RaiseException ex = runtime.newNameError("cannot load (ext) (" + className + ")", null, e, true);
ex.initCause(e); throw ex;
}
}

@Deprecated // since 9.2 only loaded with require 'core_ext/string.rb'
public static class StringUtils {
public static IRubyObject unseeded_hash(ThreadContext context, IRubyObject recv) {
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/javasupport/JavaUtilities.java
Original file line number Diff line number Diff line change
@@ -2,11 +2,14 @@

import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.StringSupport;

import static org.jruby.anno.FrameField.*;

@JRubyModule(name = "JavaUtilities")
public class JavaUtilities {
@JRubyMethod(module = true, visibility = Visibility.PRIVATE)
@@ -71,5 +74,13 @@ private static boolean validJavaIdentifier(final String javaName) {
}
return true;
}

@Deprecated // no longer used
@JRubyMethod(meta = true,
reads = { LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE },
writes = { LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE })
public static IRubyObject extend_proxy(ThreadContext context, IRubyObject recv, IRubyObject name, Block block) {
return Java.get_proxy_class(recv, name).module_eval(context, block);
}

}
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -184,10 +184,10 @@ public String[] getSuffixes() {
protected RubyArray loadPath;
protected StringArraySet loadedFeatures;
protected RubyArray loadedFeaturesDup;
private final Map<String, String> loadedFeaturesIndex = new ConcurrentHashMap<String, String>();
protected final Map<String, Library> builtinLibraries = new HashMap<String, Library>();
private final Map<String, String> loadedFeaturesIndex = new ConcurrentHashMap<>(64);
protected final Map<String, Library> builtinLibraries = new HashMap<>(36);

protected final Map<String, JarFile> jarFiles = new HashMap<String, JarFile>();
protected final Map<String, JarFile> jarFiles = new HashMap<>();

protected final Ruby runtime;
protected final LibrarySearcher librarySearcher;
15 changes: 7 additions & 8 deletions core/src/main/java/org/jruby/util/SunSignalFacade.java
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@
import org.jruby.runtime.Signature;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.CallBlock;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.BlockCallback;
import org.jruby.runtime.ThreadContext;
@@ -59,8 +58,8 @@ public class SunSignalFacade implements SignalFacade {
* to emulate {@code Signal.trap(...,"DEFAULT")} that's supposed to restore the platform
* default handler.
*/
private final Map<Signal, SignalHandler> original = new HashMap<Signal, SignalHandler>();
private final Map<String, SignalHandler> fakeOriginal = new HashMap<String, SignalHandler>();
private final Map<Signal, SignalHandler> original = new HashMap<>(4);
private final Map<String, SignalHandler> fakeOriginal = new HashMap<>(4);

private final static class JRubySignalHandler implements SignalHandler {
private final Ruby runtime;
@@ -116,7 +115,7 @@ public IRubyObject trap(final Ruby runtime, BlockCallback blk, String sig) {
}

private IRubyObject trap(final Ruby runtime, final JRubySignalHandler handler) {
return trap(runtime,handler.signal,handler);
return trap(runtime,handler.signal, handler);
}

public IRubyObject restorePlatformDefault(IRubyObject recv, IRubyObject sig) {
@@ -138,7 +137,7 @@ public IRubyObject restorePlatformDefault(IRubyObject recv, IRubyObject sig) {
synchronized (fakeOriginal) {
handler = fakeOriginal.remove(sig.toString());
}
return getSignalResult(runtime, handler, null, true);
return getSignalResult(runtime, handler, true);
}
}

@@ -173,11 +172,11 @@ private IRubyObject trap(final Ruby runtime, final String signalName, final Sign
handled = signalName.equals("EXIT");
}

return getSignalResult(runtime, oldHandler, signal, handled);
return getSignalResult(runtime, oldHandler, handled);
}

private IRubyObject getSignalResult(final Ruby runtime, final SignalHandler oldHandler, final Signal signal, boolean handled) {
IRubyObject[] retVals = new IRubyObject[] {null, runtime.newBoolean(handled)};
private static IRubyObject getSignalResult(final Ruby runtime, final SignalHandler oldHandler, boolean handled) {
IRubyObject[] retVals = new IRubyObject[] { null, runtime.newBoolean(handled) };
BlockCallback callback = null;

if (oldHandler instanceof JRubySignalHandler) {
2 changes: 0 additions & 2 deletions core/src/main/ruby/jruby/java.rb
Original file line number Diff line number Diff line change
@@ -34,7 +34,5 @@
###### END LICENSE BLOCK ######

# These are loads so they don't pollute LOADED_FEATURES
load 'jruby/java/java_utilities.rb'

load 'jruby/java/core_ext.rb'
load 'jruby/java/java_ext.rb'
15 changes: 3 additions & 12 deletions core/src/main/ruby/jruby/java/core_ext/object.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ def include_class(include_class, &block)
warn "#{__method__} is deprecated. Use java_import."
java_import(include_class, &block)
end
private :include_class

# @deprecated
def java_kind_of?(other) # TODO: this can go away now, but people may be using it
@@ -94,16 +95,6 @@ def java_import(*import_classes)
end
private :java_import

# @private
def handle_different_imports(*args, &block)
if args.first.respond_to?(:java_class)
java_import(*args, &block)
else
other_import(*args, &block)
end
end

unless respond_to?(:import)
alias :import :java_import
end
alias :import :java_import unless respond_to?(:import)

end
17 changes: 0 additions & 17 deletions core/src/main/ruby/jruby/java/java_utilities.rb

This file was deleted.

20 changes: 10 additions & 10 deletions core/src/main/ruby/jruby/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# This file boots the Ruby-based parts of JRuby.

# These are loads so they don't pollute LOADED_FEATURES
load 'jruby/kernel/jruby/type.rb'
load 'jruby/kernel/signal.rb'
require 'jruby' # NOTE: consider not doing this, require 'java' is enough!
require 'jruby/util' # stuff boot depends on (compared to a full require 'jruby')

module JRuby
autoload :ProcessUtil, 'jruby/kernel/jruby/process_util.rb'
autoload :Type, 'jruby/kernel/jruby/type.rb'
end

require 'jruby'
begin
# Try to access ProcessBuilder; if it fails, don't define our special process logic
java.lang.ProcessBuilder # GH-1148: ProcessBuilder is not available on GAE
load 'jruby/kernel/jruby/process_manager.rb'
rescue Exception
warn "ProcessBuilder unavailable; using default backtick" if $VERBOSE
# leave old backtick logic in place
end unless JRuby.runtime.posix.native? # native POSIX uses new logic for back-quote
end unless JRuby::Util.native_posix? # native POSIX uses new logic for back-quote

# These are loads so they don't pollute LOADED_FEATURES
load 'jruby/kernel/signal.rb'
load 'jruby/kernel/kernel.rb'
load 'jruby/kernel/proc.rb'
load 'jruby/kernel/process.rb'
load 'jruby/kernel/jruby/process_util.rb'
load 'jruby/kernel/jruby/type.rb'
load 'jruby/kernel/enumerator.rb'
load 'jruby/kernel/enumerable.rb'
load 'jruby/kernel/io.rb'
load 'jruby/kernel/time.rb'
load 'jruby/kernel/gc.rb'
load 'jruby/kernel/range.rb'
load 'jruby/kernel/load_error.rb'
load 'jruby/kernel/file.rb'
load 'jruby/kernel/basicobject.rb'
load 'jruby/kernel/hash.rb'
load 'jruby/kernel/string.rb'
load 'jruby/kernel/pp.rb'

$" << 'thread.rb'
$" << 'thread.rb'
4 changes: 2 additions & 2 deletions core/src/main/ruby/jruby/kernel/file.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Windows symlink support borrowed from djberg96/win32-file and ffi-win32-extensions

if org.jruby.platform.Platform::IS_WINDOWS
if JRuby::Util::ON_WINDOWS

begin
require 'ffi'
@@ -146,7 +146,7 @@ def wincode
end

# flock support for Solaris
if org.jruby.platform.Platform::IS_SOLARIS
if JRuby::Util::ON_SOLARIS
begin
require 'ffi'
rescue LoadError
55 changes: 31 additions & 24 deletions core/src/main/ruby/jruby/kernel/gc.rb
Original file line number Diff line number Diff line change
@@ -70,12 +70,10 @@ def self.stat(all_stats_or_key = {})
module Profiler
def self.__setup__
@profiler ||= begin
java.lang.Class.forName('com.sun.management.GarbageCollectionNotificationInfo')

# class exists, proceed with GC notification version
@profiler = NotifiedProfiler.new
rescue java.lang.ClassNotFoundException
@profiler = NormalProfiler.new
NotifiedProfiler.new!
# class exists and Java dependecies are also present, proceed with GC notification version
rescue NameError
NormalProfiler.new
end
end

@@ -115,35 +113,42 @@ def self.total_time
end

begin
javax.management.NotificationListener # try to access
class NotifiedProfiler
HEADER = " ID Type Timestamp(sec) Before(kB) After(kB) Delta(kB) Heap(kB) GC Time(ms) \n"
FORMAT = "%5d %-20s %19.4f %13i %13i %12i %15i %20.10f\n"

class GCListener
include javax.management.NotificationListener

def initialize
@lines = []
end

attr_accessor :lines

def handleNotification(notification, o)
lines << notification
end

def clear
lines.clear
end
def self.new!
javax.management.NotificationListener # try to access
com.sun.management.GarbageCollectionNotificationInfo
new
end

def enabled?
@gc_listener != nil
end

def enable
@gc_listener ||= GCListener.new
@gc_listener ||= begin
# delay JI class-loading, generate listener on first use :
gc_listener = Class.new do # GCListener
include javax.management.NotificationListener

def initialize
@lines = []
end

attr_accessor :lines

def handleNotification(notification, o)
lines << notification
end

def clear
lines.clear
end
end
gc_listener.new
end
java.lang.management.ManagementFactory.garbage_collector_mx_beans.each do |gc_bean|
gc_bean.add_notification_listener @gc_listener, nil, nil
end
@@ -233,6 +238,7 @@ def total_time
return duration / 1000.0
end
end
private_constant :NotifiedProfiler
rescue Exception
# ignore, leave it undefined
end
@@ -278,6 +284,7 @@ def total_time
(time - @start_time) / 1000.0
end
end
private_constant :NormalProfiler
end
end
end
11 changes: 5 additions & 6 deletions core/src/main/ruby/jruby/kernel/gem_prelude.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
if defined?(Gem)
if Object.const_defined?(:Gem)
begin
require 'rubygems'
rescue LoadError
# For JRUBY-5333, gracefully fail to load, since stdlib may not be available
require 'rubygems.rb'
rescue LoadError # java -jar lib/jruby.jar -e '...'
warn 'RubyGems not found; disabling gems' if $VERBOSE
else
begin
gem 'did_you_mean'
require 'did_you_mean'
Gem.clear_paths
rescue Gem::LoadError, LoadError
end if defined?(DidYouMean)
rescue LoadError # Gem::LoadError < LoadError
end if Object.const_defined?(:DidYouMean)
end
end
3 changes: 0 additions & 3 deletions core/src/main/ruby/jruby/kernel/load_error.rb

This file was deleted.

10 changes: 1 addition & 9 deletions core/src/main/ruby/jruby/kernel/pp.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
module Kernel
def pp(*objs)
require 'pp'
pp(*objs)
end

# suppress redefinition warning
alias pp pp # :nodoc:
end
# loaded from 'jruby/kernel/prelude.rb'
17 changes: 0 additions & 17 deletions core/src/main/ruby/jruby/kernel/prelude.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
class Thread
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc:

# call-seq:
# Thread.exclusive { block } => obj
#
# Wraps the block in a single, VM-global Mutex.synchronize, returning the
# value of the block. A thread executing inside the exclusive section will
# only block other threads which also use the Thread.exclusive mechanism.
def self.exclusive
warn "Thread.exclusive is deprecated, use Mutex", caller
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
yield
}
end
end

# :stopdoc:
class Binding
def irb
6 changes: 3 additions & 3 deletions core/src/main/ruby/jruby/kernel/proc.rb
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def curry(curried_arity = nil)
# otherwise looks just like Proc in every way. This allows us to override
# the methods with different behavior without constructing a singleton every
# time a proc is curried by using some JRuby-specific tricks below.
curried_prototype = proc{}
curried_prototype = proc {}
curried_prototype.instance_eval do
def binding
raise ArgumentError, "cannot create binding from f proc"
@@ -52,7 +52,7 @@ def source_location
end

# Yank the singleton class out of the curried prototype object.
Curried = JRuby.reference(curried_prototype).meta_class
Curried = curried_prototype
private_constant :Curried

def self.__make_curry_proc__(proc, passed, arity)
@@ -70,7 +70,7 @@ def self.__make_curry_proc__(proc, passed, arity)
end

# Replace the curried proc's class with our prototype singleton class
JRuby.reference(f).meta_class = Curried
JRuby.send(:set_meta_class, f, Curried)

f
end
26 changes: 12 additions & 14 deletions core/src/main/ruby/jruby/kernel/signal.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module Signal

SIGNALS = {
0 => "SIGEXIT",
1 => "SIGHUP", 2 => "SIGINT", 3 => "SIGQUIT", 4 => "SIGILL", 5 => "SIGTRAP", 6 => "SIGABRT",
7 => "SIGPOLL", 8 => "SIGFPE", 9 => "SIGKILL", 10 => "SIGBUS", 11 => "SIGSEGV", 12 => "SIGSYS",
13 => "SIGPIPE", 14 => "SIGALRM", 15 => "SIGTERM", 16 => "SIGURG", 17 => "SIGSTOP", 18 => "SIGTSTP",
19 => "SIGCONT", 20 => "SIGCHLD", 21 => "SIGTTIN", 22 => "SIGTTOU", 24 => "SIGXCPU", 25 => "SIGXFSZ",
26 => "SIGVTALRM", 27 => "SIGPROF", 30 => "SIGUSR1", 31 => "SIGUSR2"
}
private_constant :SIGNALS

def trap(sig, cmd = nil, &block)
sig = SIGNALS[sig] if sig.kind_of?(Integer)
sig = sig.to_s.sub(/^SIG(.+)/,'\1')

if RESERVED_SIGNALS.include?(sig)
if %w(SEGV BUS ILL FPE VTALRM).include?(sig)
raise ArgumentError.new("can't trap reserved signal: SIG%s" % sig)
end

@@ -47,16 +58,3 @@ def trap(sig, cmd = nil, &block)
end
module_function :trap
end

class Object
SIGNALS = {
0 => "SIGEXIT",
1 => "SIGHUP", 2 => "SIGINT", 3 => "SIGQUIT", 4 => "SIGILL", 5 => "SIGTRAP", 6 => "SIGABRT",
7 => "SIGPOLL", 8 => "SIGFPE", 9 => "SIGKILL", 10 => "SIGBUS", 11 => "SIGSEGV", 12 => "SIGSYS",
13 => "SIGPIPE", 14 => "SIGALRM", 15 => "SIGTERM", 16 => "SIGURG", 17 => "SIGSTOP", 18 => "SIGTSTP",
19 => "SIGCONT", 20 => "SIGCHLD", 21 => "SIGTTIN", 22 => "SIGTTOU", 24 => "SIGXCPU", 25 => "SIGXFSZ",
26 => "SIGVTALRM", 27 => "SIGPROF", 30 => "SIGUSR1", 31 => "SIGUSR2"
}

RESERVED_SIGNALS = %w(SEGV BUS ILL FPE VTALRM)
end
4 changes: 1 addition & 3 deletions lib/ruby/stdlib/date.rb
Original file line number Diff line number Diff line change
@@ -162,10 +162,8 @@
# DateTime instance will use the time zone offset of this
# instance.

org.jruby.ext.date.DateLibrary.load JRuby.runtime

require 'date/format'
require 'date.jar'
require 'date/format'

# Class representing a date.
#
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/jruby/core_ext/string.rb
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@ def unseeded_hash; end if false

end

JRuby.send(:load_string_ext)
JRuby::Util.load_ext(:string)
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/rubygems/defaults/jruby.rb
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ def spec_directories_from_classpath
JRuby::Util.extra_gem_paths.each do |path|
stuff << File.join(path, 'specifications')
end
stuff += JRuby::Util.classloader_resources('specifications')
stuff += JRuby::Util.class_loader_resources('specifications', path: true)
# some classloader return directory info.
# use only the "protocols" which jruby understands
stuff.select { |s| File.directory?( s ) }
3 changes: 1 addition & 2 deletions lib/ruby/stdlib/securerandom.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: us-ascii -*-
# frozen_string_literal: true

require 'jruby'
org.jruby.ext.securerandom.SecureRandomLibrary.load JRuby.runtime
require 'securerandom.jar'

# == Secure random number generator interface.
#

0 comments on commit 459262a

Please sign in to comment.