Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
* truffle/src/main/java/org/jruby/truffle/nodes/core/CoreMethodNodeManager.java
* truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
eregon committed Oct 8, 2015
2 parents 0d1202c + 648bfaa commit 2651d7d
Showing 50 changed files with 492 additions and 683 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Main.java
Original file line number Diff line number Diff line change
@@ -351,7 +351,7 @@ private Status handleOutOfMemory(OutOfMemoryError oome) {

String oomeMessage = oome.getMessage();

if (oomeMessage.contains("PermGen")) { // report permgen memory error
if (oomeMessage != null && oomeMessage.contains("PermGen")) { // report permgen memory error
config.getError().println("Error: Your application exhausted PermGen area of the heap.");
config.getError().println("Specify -J-XX:MaxPermSize=###M to increase it (### = PermGen size in MB).");

15 changes: 1 addition & 14 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -3573,20 +3573,7 @@ private RubyString getStringForPattern(IRubyObject obj) {
*/
private RubyRegexp getPattern(IRubyObject obj) {
if (obj instanceof RubyRegexp) return (RubyRegexp)obj;
return RubyRegexp.newRegexp(getRuntime(), getStringForPattern(obj).value);
}

private Regex getStringPattern19(Ruby runtime, IRubyObject obj) {
RubyString str = getStringForPattern(obj);
if (str.scanForCodeRange() == CR_BROKEN) {
throw runtime.newRegexpError("invalid multybyte character: " +
RegexpSupport.regexpDescription19(runtime, str.value, new RegexpOptions(), str.value.getEncoding()).toString());
}
if (str.value.getEncoding().isDummy()) {
throw runtime.newArgumentError("can't make regexp with dummy encoding");
}

return RubyRegexp.getQuotedRegexpFromCache19(runtime, str.value, new RegexpOptions(), str.isAsciiOnly());
return RubyRegexp.newRegexpFromStr(getRuntime(), getStringForPattern(obj), 0);
}

// MRI: get_pat_quoted
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# jruby/jruby#3267
# String passed to String#match was not following proper channels to compile to Regexp.
# As a result, encoding was not negotiated properly.
describe "A UTF-8 string matched against a US-ASCII string" do
it "compiles to regexp successfully" do
result = nil
expect(
lambda {result = "".force_encoding('US-ASCII').match("Període\\ de\\ retorn".force_encoding('UTF-8'))}
).not_to raise_error

expect(result).to eq(nil)
end
end
5 changes: 5 additions & 0 deletions spec/ruby/language/alias_spec.rb
Original file line number Diff line number Diff line change
@@ -157,4 +157,9 @@ def test_with_check(*args)
end
end.should raise_error(TypeError)
end

it "on top level defines the alias on Object" do
# because it defines on the default definee / current module
ruby_exe("def foo; end; alias bla foo; print method(:bla).owner", escape: true).should == "Object"
end
end
1 change: 1 addition & 0 deletions spec/truffle/tags/language/alias_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slow:The alias keyword on top level defines the alias on Object
3 changes: 1 addition & 2 deletions test/mri/excludes/TestRegexp.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
exclude :test_char_class, "needs investigation"
exclude :test_dup_warn, "needs investigation"
exclude :test_eq_tilde_can_be_overridden, "needs investigation"
exclude :test_equal, "needs investigation"
exclude :test_initialize, "needs investigation"
exclude :test_invalid_escape_error, "needs investigation"
exclude :test_invalid_fragment, "needs investigation"
exclude :test_named_capture_nonascii, "needs investigation"
exclude :test_once_multithread, "needs investigation"
exclude :test_once_multithread, "fails intermittently"
exclude :test_options_in_look_behind, "needs investigation"
exclude :test_raw_hyphen_and_tk_char_type_after_range, "needs investigation"
exclude :test_regsub_K, "needs investigation"
2 changes: 0 additions & 2 deletions test/mri/excludes/TestString.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
exclude :test_count, "needs investigation"
exclude :test_eq_tilde_can_be_overridden, "needs investigation"
exclude :test_partition, "needs investigation"
exclude :test_regexp_match_subclass, "String subclass with overridden =~ should see obj =~ dispatch (#2157)"
exclude :test_rpartition, "needs investigation"
exclude :test_rstrip, "needs investigation"
exclude :test_to_i, "needs investigation"
Original file line number Diff line number Diff line change
@@ -54,12 +54,12 @@ protected Object autoloadConstant(VirtualFrame frame, DynamicObject module, Stri

// The autoload constant must only be removed if everything succeeds.
// We remove it first to allow lookup to ignore it and add it back if there was a failure.
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(this, name);
Layouts.MODULE.getFields(constant.getDeclaringModule()).removeConstant(getContext(), this, name);
try {
requireNode.require(path);
return readConstantNode.readConstant(frame, module, name);
} catch (RaiseException e) {
Layouts.MODULE.getFields(constant.getDeclaringModule()).setAutoloadConstant(this, name, path);
Layouts.MODULE.getFields(constant.getDeclaringModule()).setAutoloadConstant(getContext(), this, name, path);
throw e;
}
}
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public Object execute(VirtualFrame frame) {

final DynamicObject module = (DynamicObject) receiverObject;

Layouts.MODULE.getFields(module).setConstant(this, name, rhsValue);
Layouts.MODULE.getFields(module).setConstant(getContext(), this, name, rhsValue);

return rhsValue;
}
34 changes: 17 additions & 17 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ClassNodes.java
Original file line number Diff line number Diff line change
@@ -61,10 +61,10 @@ public static DynamicObject createClassClass(RubyContext context) {
* This constructor supports initialization and solves boot-order problems and should not
* normally be used from outside this class.
*/
public static DynamicObject createBootClass(DynamicObject classClass, DynamicObject superclass, String name) {
public static DynamicObject createBootClass(RubyContext context, DynamicObject classClass, DynamicObject superclass, String name) {
assert RubyGuards.isRubyClass(classClass);
assert superclass == null || RubyGuards.isRubyClass(superclass);
final ModuleFields model = new ModuleFields(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(classClass)).getContext(), null, name);
final ModuleFields model = new ModuleFields(context, null, name);

final DynamicObject rubyClass = Layouts.CLASS.createClass(Layouts.CLASS.getInstanceFactory(classClass), model, false, null, null);
assert RubyGuards.isRubyClass(rubyClass) : classClass.getShape().getObjectType().getClass();
@@ -75,7 +75,7 @@ public static DynamicObject createBootClass(DynamicObject classClass, DynamicObj
if (model.lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(rubyClass).name = Layouts.MODULE.getFields(rubyClass).givenBaseName;
} else {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(model.lexicalParent, model.givenBaseName, null);
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
}

if (superclass != null) {
@@ -97,12 +97,12 @@ public static DynamicObject createSingletonClassOfObject(RubyContext context, Dy
// Allocator is null here, we cannot create instances of singleton classes.
assert RubyGuards.isRubyClass(superclass);
assert attached == null || RubyGuards.isRubyModule(attached);
return ensureSingletonConsistency(createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), null, superclass, name, true, attached));
return ensureSingletonConsistency(context, createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), null, superclass, name, true, attached));
}

public static DynamicObject createRubyClass(RubyContext context, DynamicObject lexicalParent, DynamicObject superclass, String name) {
final DynamicObject rubyClass = createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(superclass), lexicalParent, superclass, name, false, null);
ensureSingletonConsistency(rubyClass);
ensureSingletonConsistency(context, rubyClass);
return rubyClass;
}

@@ -118,7 +118,7 @@ public static DynamicObject createRubyClass(RubyContext context, DynamicObject c
if (model.lexicalParent == null) { // bootstrap or anonymous module
Layouts.MODULE.getFields(rubyClass).name = Layouts.MODULE.getFields(rubyClass).givenBaseName;
} else {
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(model.lexicalParent, model.givenBaseName, null);
Layouts.MODULE.getFields(rubyClass).getAdoptedByLexicalParent(context, model.lexicalParent, model.givenBaseName, null);
}

if (superclass != null) {
@@ -140,33 +140,33 @@ public static DynamicObject createRubyClass(RubyContext context, DynamicObject c
}


public static void initialize(DynamicObject rubyClass, DynamicObject superclass) {
public static void initialize(RubyContext context, DynamicObject rubyClass, DynamicObject superclass) {
assert RubyGuards.isRubyClass(superclass);

Layouts.MODULE.getFields(rubyClass).parentModule = Layouts.MODULE.getFields(superclass).start;
Layouts.MODULE.getFields(superclass).addDependent(rubyClass);

Layouts.MODULE.getFields(rubyClass).newVersion();
ensureSingletonConsistency(rubyClass);
ensureSingletonConsistency(context, rubyClass);

DynamicObjectFactory factory = Layouts.CLASS.getInstanceFactory(superclass);
factory = Layouts.BASIC_OBJECT.setLogicalClass(factory, rubyClass);
factory = Layouts.BASIC_OBJECT.setMetaClass(factory, rubyClass);
Layouts.CLASS.setInstanceFactoryUnsafe(rubyClass, factory);
}

public static DynamicObject ensureSingletonConsistency(DynamicObject rubyClass) {
createOneSingletonClass(rubyClass);
public static DynamicObject ensureSingletonConsistency(RubyContext context, DynamicObject rubyClass) {
createOneSingletonClass(context, rubyClass);
return rubyClass;
}

public static DynamicObject getSingletonClass(DynamicObject rubyClass) {
public static DynamicObject getSingletonClass(RubyContext context, DynamicObject rubyClass) {
// We also need to create the singleton class of a singleton class for proper lookup and consistency.
// See rb_singleton_class() documentation in MRI.
return ensureSingletonConsistency(createOneSingletonClass(rubyClass));
return ensureSingletonConsistency(context, createOneSingletonClass(context, rubyClass));
}

public static DynamicObject createOneSingletonClass(DynamicObject rubyClass) {
public static DynamicObject createOneSingletonClass(RubyContext context, DynamicObject rubyClass) {
CompilerAsserts.neverPartOfCompilation();

if (Layouts.CLASS.getIsSingleton(Layouts.BASIC_OBJECT.getMetaClass(rubyClass))) {
@@ -177,11 +177,11 @@ public static DynamicObject createOneSingletonClass(DynamicObject rubyClass) {
if (getSuperClass(rubyClass) == null) {
singletonSuperclass = Layouts.BASIC_OBJECT.getLogicalClass(rubyClass);
} else {
singletonSuperclass = createOneSingletonClass(getSuperClass(rubyClass));
singletonSuperclass = createOneSingletonClass(context, getSuperClass(rubyClass));
}

String name = String.format("#<Class:%s>", Layouts.MODULE.getFields(rubyClass).getName());
Layouts.BASIC_OBJECT.setMetaClass(rubyClass, ClassNodes.createRubyClass(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(rubyClass)).getContext(), Layouts.BASIC_OBJECT.getLogicalClass(rubyClass), null, singletonSuperclass, name, true, rubyClass));
Layouts.BASIC_OBJECT.setMetaClass(rubyClass, ClassNodes.createRubyClass(context, Layouts.BASIC_OBJECT.getLogicalClass(rubyClass), null, singletonSuperclass, name, true, rubyClass));

return Layouts.BASIC_OBJECT.getMetaClass(rubyClass);
}
@@ -286,7 +286,7 @@ private DynamicObject initializeGeneralWithoutBlock(VirtualFrame frame, DynamicO
assert RubyGuards.isRubyClass(rubyClass);
assert RubyGuards.isRubyClass(superclass);

ClassNodes.initialize(rubyClass, superclass);
ClassNodes.initialize(getContext(), rubyClass, superclass);
triggerInheritedHook(frame, rubyClass, superclass);

return rubyClass;
@@ -297,7 +297,7 @@ private DynamicObject initializeGeneralWithBlock(VirtualFrame frame, DynamicObje
assert RubyGuards.isRubyClass(superclass);
assert RubyGuards.isRubyProc(block);

ClassNodes.initialize(rubyClass, superclass);
ClassNodes.initialize(getContext(), rubyClass, superclass);
triggerInheritedHook(frame, rubyClass, superclass);
moduleInitialize(frame, rubyClass, block);

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
@@ -42,12 +43,11 @@

public class CoreMethodNodeManager {

private final DynamicObject objectClass;
private final RubyContext context;
private final SingletonClassNode singletonClassNode;

public CoreMethodNodeManager(DynamicObject objectClass, SingletonClassNode singletonClassNode) {
assert RubyGuards.isRubyClass(objectClass);
this.objectClass = objectClass;
public CoreMethodNodeManager(RubyContext context, SingletonClassNode singletonClassNode) {
this.context = context;
this.singletonClassNode = singletonClassNode;
}

@@ -69,15 +69,13 @@ private DynamicObject getSingletonClass(Object object) {
}

private void addCoreMethod(MethodDetails methodDetails) {
final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(objectClass)).getContext();

DynamicObject module;
String fullName = methodDetails.getClassAnnotation().name();

if (fullName.equals("main")) {
module = getSingletonClass(context.getCoreLibrary().getMainObject());
} else {
module = objectClass;
module = context.getCoreLibrary().getObjectClass();

for (String moduleName : fullName.split("::")) {
final RubyConstant constant = ModuleOperations.lookupConstant(context, module, moduleName);
@@ -120,16 +118,16 @@ private void addCoreMethod(MethodDetails methodDetails) {
final RubyRootNode rootNode = makeGenericMethod(context, methodDetails);

if (method.isModuleFunction()) {
addMethod(module, rootNode, names, Visibility.PRIVATE);
addMethod(getSingletonClass(module), rootNode, names, Visibility.PUBLIC);
addMethod(context, module, rootNode, names, Visibility.PRIVATE);
addMethod(context, getSingletonClass(module), rootNode, names, Visibility.PUBLIC);
} else if (method.onSingleton() || method.constructor()) {
addMethod(getSingletonClass(module), rootNode, names, visibility);
addMethod(context, getSingletonClass(module), rootNode, names, visibility);
} else {
addMethod(module, rootNode, names, visibility);
addMethod(context, module, rootNode, names, visibility);
}
}

private static void addMethod(DynamicObject module, RubyRootNode rootNode, List<String> names, final Visibility originalVisibility) {
private static void addMethod(RubyContext context, DynamicObject module, RubyRootNode rootNode, List<String> names, final Visibility originalVisibility) {
assert RubyGuards.isRubyModule(module);

for (String name : names) {
@@ -143,7 +141,7 @@ private static void addMethod(DynamicObject module, RubyRootNode rootNode, List<
final InternalMethod method = new InternalMethod(rootNodeCopy.getSharedMethodInfo(), name, module, visibility, false,
Truffle.getRuntime().createCallTarget(rootNodeCopy), null);

Layouts.MODULE.getFields(module).addMethod(null, method.withVisibility(visibility).withName(name));
Layouts.MODULE.getFields(module).addMethod(context, null, method.withVisibility(visibility).withName(name));
}
}

Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ public DynamicObject initialize(DynamicObject self, Object source, Object destin
// by Rubinius. Rubinius will do the heavy lifting of parsing the options hash and setting the `@options`
// ivar to the resulting int for EConv flags. Since we don't pass the proper data structures to EncodingUtils,
// we must override the flags after its had a pass in order to correct the bad flags value.
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(self)).getContext().getCoreLibrary().getNilObject()));
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", getContext().getCoreLibrary().getNilObject()));

EConv econv = EncodingUtils.econvOpenOpts(runtime.getCurrentContext(), encNames[0], encNames[1], ecflags[0], ecopts[0]);

Original file line number Diff line number Diff line change
@@ -33,22 +33,20 @@
public abstract class ExceptionNodes {

@TruffleBoundary
public static DynamicObject asRubyStringArray(DynamicObject exception) {
public static DynamicObject asRubyStringArray(RubyContext context, DynamicObject exception) {
assert RubyGuards.isRubyException(exception);
assert Layouts.EXCEPTION.getBacktrace(exception) != null;

final RubyContext context = Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext();

final List<String> lines = new BacktraceFormatter(context, EnumSet.of(BacktraceFormatter.FormattingFlags.OMIT_FROM_PREFIX))
.formatBacktrace(exception, Layouts.EXCEPTION.getBacktrace(exception));

final Object[] array = new Object[lines.size()];

for (int n = 0;n < lines.size(); n++) {
array[n] = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getStringClass()), StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
array[n] = Layouts.STRING.createString(Layouts.CLASS.getInstanceFactory(context.getCoreLibrary().getStringClass()), StringOperations.encodeByteList(lines.get(n), UTF8Encoding.INSTANCE), StringSupport.CR_UNKNOWN, null);
}

return Layouts.ARRAY.createArray(Layouts.MODULE.getFields(Layouts.BASIC_OBJECT.getLogicalClass(exception)).getContext().getCoreLibrary().getArrayFactory(), array, array.length);
return Layouts.ARRAY.createArray(context.getCoreLibrary().getArrayFactory(), array, array.length);
}

public static void setMessage(DynamicObject exception, Object message) {
@@ -100,7 +98,7 @@ public Object backtrace(DynamicObject exception) {
if (customBacktrace != null) {
return customBacktrace;
} else if (Layouts.EXCEPTION.getBacktrace(exception) != null) {
return asRubyStringArray(exception);
return asRubyStringArray(getContext(), exception);
} else {
return nil();
}
Loading

0 comments on commit 2651d7d

Please sign in to comment.