Skip to content

Commit

Permalink
Merge pull request #5205 from jruby/ji-lazy-pp2
Browse files Browse the repository at this point in the history
review (cleanup) boot -> standard JRuby extension loading
  • Loading branch information
kares committed Jun 28, 2018
2 parents 39d1ba3 + 4ad609e commit 459262a
Show file tree
Hide file tree
Showing 25 changed files with 312 additions and 251 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyLoadError.java
Expand Up @@ -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;
}

Expand Down
136 changes: 68 additions & 68 deletions core/src/main/java/org/jruby/RubySignal.java
Expand Up @@ -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();
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 459262a

Please sign in to comment.