Skip to content

Commit

Permalink
Showing 84 changed files with 1,317 additions and 1,132 deletions.
35 changes: 29 additions & 6 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@
import org.jruby.compiler.Constantizable;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ext.thread.ThreadLibrary;
import org.jruby.ir.IRScope;
import org.jruby.ir.IRScriptBody;
import org.jruby.javasupport.JavaSupport;
import org.jruby.javasupport.JavaSupportImpl;
@@ -540,12 +541,11 @@ public void runFromMain(InputStream inputStream, String filename) {

if (filename.endsWith(".class")) {
// we are presumably running a precompiled class; load directly
Script script = CompiledScriptLoader.loadScriptFromFile(this, inputStream, filename);
IRScope script = CompiledScriptLoader.loadScriptFromFile(this, inputStream, null, filename, false);
if (script == null) {
throw new MainExitException(1, "error: .class file specified is not a compiled JRuby script");
}
script.setFilename(filename);
runScript(script);
runInterpreter(script);
return;
}

@@ -2685,7 +2685,7 @@ public ParseResult parseFile(String file, InputStream in, DynamicScope scope, in

try {
// Get IR from .ir file
return IRReader.load(getIRManager(), new IRReaderStream(getIRManager(), IRFileExpert.getIRPersistedFile(file)));
return IRReader.load(getIRManager(), new IRReaderStream(getIRManager(), IRFileExpert.getIRPersistedFile(file), new ByteList(file.getBytes())));
} catch (IOException e) {
// FIXME: What is something actually throws IOException
return parseFileAndGetAST(in, file, scope, lineNumber, false);
@@ -2706,7 +2706,7 @@ public ParseResult parseFileFromMain(String file, InputStream in, DynamicScope s
if (!RubyInstanceConfig.IR_READING) return parseFileFromMainAndGetAST(in, file, scope);

try {
return IRReader.load(getIRManager(), new IRReaderStream(getIRManager(), IRFileExpert.getIRPersistedFile(file)));
return IRReader.load(getIRManager(), new IRReaderStream(getIRManager(), IRFileExpert.getIRPersistedFile(file), new ByteList(file.getBytes())));
} catch (IOException e) {
System.out.println(e);
e.printStackTrace();
@@ -2905,6 +2905,27 @@ public void loadFile(String scriptName, InputStream in, boolean wrap) {
}
}

public void loadScope(IRScope scope, boolean wrap) {
IRubyObject self = wrap ? TopSelfFactory.createTopSelf(this, true) : getTopSelf();
ThreadContext context = getCurrentContext();
String file = context.getFile();

try {
ThreadContext.pushBacktrace(context, "(root)", file, 0);
context.preNodeEval(self);

if (wrap) {
// toss an anonymous module into the search path
scope.getStaticScope().setModule(RubyModule.newModule(this));
}

runInterpreter(context, scope, self);
} finally {
context.postNodeEval();
ThreadContext.popBacktrace(context);
}
}

public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
InputStream readStream = in;

@@ -3109,7 +3130,9 @@ public void setTraceFunction(RubyProc traceFunction) {

public void callEventHooks(ThreadContext context, RubyEvent event, String file, int line, String name, IRubyObject type) {
if (context.isEventHooksEnabled()) {
for (EventHook eventHook : eventHooks) {
for (int i = 0; i < eventHooks.length; i++) {
EventHook eventHook = eventHooks[i];

if (eventHook.isInterestedInEvent(event)) {
eventHook.event(context, event, file, line, name, type);
}
22 changes: 14 additions & 8 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -573,15 +573,21 @@ public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
return op_pow19(context, other);
}

public IRubyObject op_pow(ThreadContext context, long other) {
// MRI issuses warning here on (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024)
if (((value.bitLength() + 7) / 8) * 4 * Math.abs(other) > 1024 * 1024) {
getRuntime().getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
}
public IRubyObject op_pow(final ThreadContext context, final long other) {
warnIfPowExponentTooBig(context, other);

if (other >= 0) {
return bignorm(getRuntime(), value.pow((int) other)); // num2int is also implemented
} else {
return RubyFloat.newFloat(getRuntime(), Math.pow(big2dbl(this), (double)other));
if ( other <= Integer.MAX_VALUE ) { // only have BigInteger#pow(int)
return bignorm(context.runtime, value.pow((int) other)); // num2int is also implemented
}
}
return RubyFloat.newFloat(context.runtime, Math.pow(big2dbl(this), (double) other));
}

private void warnIfPowExponentTooBig(final ThreadContext context, final double other) {
// MRI issuses warning here on (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024)
if ( ((value.bitLength() + 7) / 8) * 4 * Math.abs(other) > 1024 * 1024 ) {
context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
}
}

12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -472,9 +472,10 @@ public IRubyObject inspect() {
val.append(">");
return getRuntime().newString(val.toString());
}


private static Pattern ROOT_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?$");

/* File class methods */

@JRubyMethod(required = 1, optional = 1, meta = true)
public static IRubyObject basename(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
@@ -483,6 +484,11 @@ public static IRubyObject basename(ThreadContext context, IRubyObject recv, IRub
Encoding origEncoding = origString.getEncoding();
String name = origString.toString();

// uri-like paths without parent directory
if (name.endsWith("!/") || ROOT_PATTERN.matcher(name).matches()) {
return args[0];
}

// MRI-compatible basename handling for windows drive letter paths
if (Platform.IS_WINDOWS) {
if (name.length() > 1 && name.charAt(1) == ':' && Character.isLetter(name.charAt(0))) {
@@ -628,7 +634,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^([a-z]+:)?[a-z]+:/.*");
private static Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");
public static String dirname(ThreadContext context, String jfilename) {
String name = jfilename.replace('\\', '/');
int minPathLength = 1;
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -4871,13 +4871,19 @@ public static IRubyObject popen4(ThreadContext context, IRubyObject recv, IRubyO
@Deprecated
private static void cleanupPOpen(POpenTuple tuple) {
if (tuple.input.openFile.isOpen()) {
tuple.input.close();
try {
tuple.input.close();
} catch (RaiseException re) {}
}
if (tuple.output.openFile.isOpen()) {
tuple.output.close();
try {
tuple.output.close();
} catch (RaiseException re) {}
}
if (tuple.error.openFile.isOpen()) {
tuple.error.close();
try {
tuple.error.close();
} catch (RaiseException re) {}
}
}

7 changes: 0 additions & 7 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -1628,13 +1628,6 @@ public boolean shouldPrecompileAll() {
public static boolean FASTSEND_COMPILE_ENABLED
= FASTEST_COMPILE_ENABLED || Options.COMPILE_FASTSEND.load();

/**
* Enable lazy handles optimizations.
*
* Set with the <tt>jruby.compile.lazyHandles</tt> system property.
*/
public static boolean LAZYHANDLES_COMPILE = Options.COMPILE_LAZYHANDLES.load();

/**
* Enable fast multiple assignment optimization.
*
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -779,7 +779,7 @@ public synchronized void prependModule(IRubyObject arg) {
// Make sure the module we include does not already exist
checkForCyclicInclude(module);

if (hasModuleInHierarchy((RubyModule)arg)) {
if (hasModuleInHierarchy((RubyModule) arg)) {
invalidateCacheDescendants();
return;
}
@@ -965,8 +965,8 @@ public Map<String, List<JavaMethodDescriptor>> getStaticAnnotatedMethods() {
public void defineAnnotatedMethodsIndividually(Class clazz) {
TypePopulator populator;

if (RubyInstanceConfig.FULL_TRACE_ENABLED || RubyInstanceConfig.REFLECTED_HANDLES) {
// we want reflected invokers or need full traces, use default (slow) populator
if (Options.DEBUG_FULLTRACE.load() || Options.REFLECTED_HANDLES.load() || Options.INVOKEDYNAMIC_HANDLES.load()) {
// we want non-generated invokers or need full traces, use default (slow) populator
if (DEBUG) LOG.info("trace mode, using default populator");
populator = TypePopulator.DEFAULT;
} else {
@@ -4154,6 +4154,7 @@ private static void define(RubyModule module, JavaMethodDescriptor desc, String
singletonClass = module.getSingletonClass();
// module/singleton methods are all defined public
DynamicMethod moduleMethod = dynamicMethod.dup();
moduleMethod.setImplementationClass(singletonClass);
moduleMethod.setVisibility(PUBLIC);

if (jrubyMethod.name().length == 0) {
12 changes: 0 additions & 12 deletions core/src/main/java/org/jruby/anno/TypePopulator.java
Original file line number Diff line number Diff line change
@@ -80,18 +80,6 @@ public void populate(RubyModule clsmod, Class clazz) {

RubyModule.MethodClumper clumper = new RubyModule.MethodClumper();
clumper.clump(clazz);

for (Map.Entry<String, List<JavaMethodDescriptor>> entry : clumper.getAllAnnotatedMethods().entrySet()) {
for (JavaMethodDescriptor desc : entry.getValue()) {
JRubyMethod anno = desc.anno;

// check for frame field reads or writes
if (anno.frame() || (anno.reads() != null && anno.reads().length >= 1) || (anno.writes() != null && anno.writes().length >= 1)) {
// add all names for this annotation
MethodIndex.addFrameAwareMethods(anno.name());
}
}
}

for (Map.Entry<String, List<JavaMethodDescriptor>> entry : clumper.getStaticAnnotatedMethods().entrySet()) {
clsmod.defineAnnotatedMethod(entry.getKey(), entry.getValue(), methodFactory);
Original file line number Diff line number Diff line change
@@ -63,7 +63,18 @@ public OSGiLoadService(Ruby runtime) {
super(runtime);
// super.searchers.add(new OSGiBundlesSearcher());
}


protected Library findLibraryBySearchState(SearchState state) {
Library library = super.findLibraryBySearchState(state);
if (library == null){
library = findLibraryWithClassloaders(state, state.searchFile, state.suffixType);
if (library != null) {
state.library = library;
}
}
return library;
}

/**
* Support for 'bundle:/' to look for libraries in osgi bundles
* or classes or ruby files.
Loading

0 comments on commit 0ddeeeb

Please sign in to comment.