Skip to content

Commit

Permalink
Showing 28 changed files with 834 additions and 342 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -60,15 +60,6 @@ matrix:
# group: edge
# jdk: oraclejdk9

branches:
only:
- master
- jruby-1_7
- truffle-head
- /^test-.*$/
- /^ha-feature/
- ruby-2.4

install: tool/travis-install.sh
script: tool/travis-script.sh

65 changes: 14 additions & 51 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3015,61 +3015,24 @@ public void loadScope(IRScope scope, boolean wrap) {
public void compileAndLoadFile(String filename, InputStream in, boolean wrap) {
InputStream readStream = in;

Script script = null;

try {
// read full contents of file, hash it, and try to load that class first
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int num;
while ((num = in.read(buffer)) > -1) {
baos.write(buffer, 0, num);
}
buffer = baos.toByteArray();
String hash = JITCompiler.getHashForBytes(buffer);
final String className = JITCompiler.RUBY_JIT_PREFIX + ".FILE_" + hash;

// FIXME: duplicated from ClassCache
Class contents;
try {
contents = getJRubyClassLoader().loadClass(className);
if (LOG.isDebugEnabled()) { // RubyInstanceConfig.JIT_LOADING_DEBUG
LOG.debug("found jitted code for " + filename + " at class: " + className);
}
script = (Script) contents.newInstance();
readStream = new ByteArrayInputStream(buffer);
} catch (ClassNotFoundException cnfe) {
if (LOG.isDebugEnabled()) { // RubyInstanceConfig.JIT_LOADING_DEBUG
LOG.debug("no jitted code in classloader for file " + filename + " at class: " + className);
}
} catch (InstantiationException ex) {
if (LOG.isDebugEnabled()) { // RubyInstanceConfig.JIT_LOADING_DEBUG
LOG.debug("jitted code could not be instantiated for file " + filename + " at class: " + className + ' ' + ex);
}
} catch (IllegalAccessException ex) {
if (LOG.isDebugEnabled()) { // RubyInstanceConfig.JIT_LOADING_DEBUG
LOG.debug("jitted code could not be instantiated for file " + filename + " at class: " + className + ' ' + ex);
}
}
} catch (IOException ioe) {
// TODO: log something?
}

// script was not found in cache above, so proceed to compile
RootNode scriptNode = (RootNode) parseFile(readStream, filename, null);
if (script == null) {
ScriptAndCode scriptAndCode = tryCompile(scriptNode,
new ClassDefiningJRubyClassLoader(getJRubyClassLoader())
);
if (scriptAndCode != null) script = scriptAndCode.script();
}

if (script == null) {
failForcedCompile(scriptNode);
ThreadContext context = getCurrentContext();

runInterpreter(scriptNode);
} else {
runScript(script, wrap);
String oldFile = context.getFile();
int oldLine = context.getLine();
try {
context.setFileAndLine(scriptNode.getFile(), scriptNode.getLine());

if (config.isAssumePrinting() || config.isAssumeLoop()) {
runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
config.isSplit());
} else {
runNormally(scriptNode);
}
} finally {
context.setFileAndLine(oldFile, oldLine);
}
}

110 changes: 65 additions & 45 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
import org.jruby.runtime.invokedynamic.MethodNames;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.runtime.opto.Invalidator;
import org.jruby.util.ByteList;
import org.jruby.util.Pack;
import org.jruby.util.Qsort;
@@ -4193,31 +4194,37 @@ final IRubyObject dig(ThreadContext context, IRubyObject[] args, int idx) {
return idx == args.length ? val : RubyObject.dig(context, val, args, idx);
}

private IRubyObject maxWithBlock(ThreadContext context, Block block) {
IRubyObject result = UNDEF;
Ruby runtime = context.runtime;
for (int i = 0; i < realLength; i++) {
IRubyObject v = eltOk(i);

if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) > 0) {
result = v;
}
}

return result == UNDEF ? context.nil : result;
}

@JRubyMethod(name = "max")
public IRubyObject max(ThreadContext context, Block block) {
// TODO: check for overwritten <=> on Fixnum and String
// struct cmp_opt_data cmp_opt = { 0, 0 };
IRubyObject result = UNDEF, v;
int i;
if (block.isGiven()) return maxWithBlock(context, block);

if (block.isGiven()) {
Ruby runtime = context.runtime;
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) > 0) {
result = v;
}
}
} else {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || optimizedCmp(context, v, result/*, cmp_opt*/) > 0) {
result = v;
}
IRubyObject result = UNDEF;
Invalidator invalidator = getTypeIdForCMP();
Object typeId = invalidator != null ? invalidator.getData() : null;

for (int i = 0; i < realLength; i++) {
IRubyObject v = eltOk(i);

if (result == UNDEF || optimizedCmp(context, v, result, typeId, invalidator) > 0) {
result = v;
}
}
if (result == UNDEF) return context.nil;
return result;

return result == UNDEF ? context.nil : result;
}

@JRubyMethod(name = "max")
@@ -4229,32 +4236,46 @@ public IRubyObject max(ThreadContext context, IRubyObject num, Block block) {
return max(context, block);
}

@JRubyMethod(name = "min")
public IRubyObject min(ThreadContext context, Block block) {
// TODO: check for overwritten <=> on Fixnum and String
// struct cmp_opt_data cmp_opt = { 0, 0 };
IRubyObject result = UNDEF, v;
int i;
private IRubyObject minWithBlock(ThreadContext context, Block block) {
IRubyObject result = UNDEF;

if (block.isGiven()) {
Ruby runtime = context.runtime;
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) < 0) {
result = v;
}
Ruby runtime = context.runtime;
for (int i = 0; i < realLength; i++) {
IRubyObject v = eltOk(i);

if (result == UNDEF || RubyComparable.cmpint(context, block.yieldArray(context, runtime.newArray(v, result), null), v, result) < 0) {
result = v;
}
}
else {
for (i = 0; i < realLength; i++) {
v = eltOk(i);
if (result == UNDEF || optimizedCmp(context, v, result/*, cmp_opt*/) < 0) {
result = v;
}

return result == UNDEF ? context.nil : result;
}

@JRubyMethod(name = "min")
public IRubyObject min(ThreadContext context, Block block) {
if (block.isGiven()) return minWithBlock(context, block);

IRubyObject result = UNDEF;
Invalidator invalidator = getTypeIdForCMP();
Object typeId = invalidator != null ? invalidator.getData() : null;

for (int i = 0; i < realLength; i++) {
IRubyObject v = eltOk(i);

if (result == UNDEF || optimizedCmp(context, v, result, typeId, invalidator) < 0) {
result = v;
}
}
if (result == UNDEF) return context.nil;
return result;

return result == UNDEF ? context.nil : result;
}

private Invalidator getTypeIdForCMP() {
if (realLength <= 0) return null;

RubyModule meta = eltOk(0).getMetaClass();

return meta.isBuiltin(OP_CMP.realName()) ? meta.getInvalidator() : null;
}

@JRubyMethod(name = "min")
@@ -4266,13 +4287,12 @@ public IRubyObject min(ThreadContext context, IRubyObject num, Block block) {
return min(context, block);
}

private static final int optimizedCmp(ThreadContext context, IRubyObject a, IRubyObject b/*, IRubyObject data*/) {
// TODO: check for overwritten <=> on Fixnum and String
if (a instanceof RubyFixnum && b instanceof RubyFixnum /*&& CMP_OPTIMIZABLE(data, Fixnum)*/) {
private static final int optimizedCmp(ThreadContext context, IRubyObject a, IRubyObject b, Object typeId, Invalidator invalidator) {
if (a instanceof RubyFixnum && b instanceof RubyFixnum && typeId == invalidator.getData()) {
long aLong = ((RubyFixnum)a).getLongValue();
long bLong = ((RubyFixnum)b).getLongValue();
return aLong > bLong ? 1 : aLong < bLong ? -1 : 0;
} else if (a instanceof RubyString && b instanceof RubyString /*&& CMP_OPTIMIZABLE(data, String)*/) {
} else if (a instanceof RubyString && b instanceof RubyString && typeId == invalidator.getData()) {
return ((RubyString)a).op_cmp((RubyString)b);
}

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -406,9 +406,9 @@ public IRubyObject inspect() {
}
IRubyObject v = RubyRegexp.nth_match(i, this);
if (v.isNil()) {
result.cat("nil".getBytes());
result.cat(RubyNil.nilBytes); // "nil"
} else {
result.append(((RubyString)v).inspect19());
result.append(((RubyString) v).inspect(runtime));
}
}

9 changes: 7 additions & 2 deletions core/src/main/java/org/jruby/RubyNil.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import org.jcodings.specific.USASCIIEncoding;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyClass;
import org.jruby.compiler.Constantizable;
@@ -40,6 +41,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.opto.OptoFactory;
import org.jruby.util.ByteList;

/**
*
@@ -156,7 +158,7 @@ public static RubyArray to_a(ThreadContext context, IRubyObject recv) {
public static RubyHash to_h(ThreadContext context, IRubyObject recv) {
return RubyHash.newSmallHash(context.runtime);
}

/** nil_inspect
*
*/
@@ -165,8 +167,11 @@ public static RubyString inspect(ThreadContext context, IRubyObject recv) {
return inspect(context.runtime);
}

static final byte[] nilBytes = new byte[] { 'n','i','l' }; // RubyString.newUSASCIIString(runtime, "nil")
private static final ByteList nil = new ByteList(nilBytes, USASCIIEncoding.INSTANCE);

static RubyString inspect(Ruby runtime) {
return RubyString.newUSASCIIString(runtime, "nil");
return RubyString.newStringShared(runtime, runtime.getString(), nil);
}

/** nil_and
Loading

0 comments on commit 197a30c

Please sign in to comment.