Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
# Conflicts:
#	truffle/src/main/java/org/jruby/truffle/core/kernel/TraceManager.java
chrisseaton committed Feb 29, 2016

Unverified

This user has not yet uploaded their public signing key.
2 parents b0bf2cb + a67ade8 commit 49cb6c7
Showing 38 changed files with 333 additions and 216 deletions.
Original file line number Diff line number Diff line change
@@ -80,14 +80,17 @@
import org.jruby.truffle.interop.TruffleInteropNodesFactory;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.backtrace.BacktraceFormatter;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.control.TruffleFatalException;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.FreezeNode;
import org.jruby.truffle.language.objects.FreezeNodeGen;
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.language.objects.SingletonClassNodeGen;
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.platform.RubiniusTypes;
import org.jruby.truffle.platform.signal.SignalManager;
import org.jruby.truffle.stdlib.BigDecimalNodesFactory;
@@ -758,7 +761,8 @@ public void initializeAfterBasicMethodsAdded() {

state = State.LOADING_RUBY_CORE;
try {
context.getCodeLoader().load(context.getSourceCache().getSource(getCoreLoadPath() + "/core.rb"), node);
final RubyRootNode rootNode = context.getCodeLoader().parse(context.getSourceCache().getSource(getCoreLoadPath() + "/core.rb"), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, node);
context.getCodeLoader().execute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, context.getCoreLibrary().getMainObject());
} catch (IOException e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.objects.SelfNode;
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.language.translator.Translator;
import org.jruby.truffle.language.parser.jruby.Translator;

import java.lang.reflect.Method;
import java.util.ArrayList;
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.RubyContext;
@@ -32,6 +33,7 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
@@ -42,8 +44,10 @@
import org.jruby.truffle.language.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.language.supercall.SuperCallNode;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.util.ByteList;

import java.util.ArrayList;
import java.util.Arrays;
@@ -157,7 +161,10 @@ public InstanceEvalNode(RubyContext context, SourceSection sourceSection) {
@CompilerDirectives.TruffleBoundary
@Specialization(guards = "isRubyString(string)")
public Object instanceEval(Object receiver, DynamicObject string, NotProvided block) {
return getContext().getCodeLoader().instanceEval(StringOperations.getByteListReadOnly(string), receiver, "(eval)", this);
ByteList code = StringOperations.getByteListReadOnly(string);
final Source source = Source.fromText(code, "(eval)");
final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, code.getEncoding(), ParserContext.EVAL, null, true, this);
return getContext().getCodeLoader().execute(ParserContext.EVAL, DeclarationContext.INSTANCE_EVAL, rootNode, null, receiver);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -100,6 +100,8 @@
import org.jruby.truffle.language.dispatch.DoesRespondDispatchHeadNode;
import org.jruby.truffle.language.dispatch.MissingBehavior;
import org.jruby.truffle.language.loader.FeatureLoader;
import org.jruby.truffle.language.loader.SourceLoader;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.LookupMethodNode;
import org.jruby.truffle.language.methods.LookupMethodNodeGen;
@@ -124,12 +126,13 @@
import org.jruby.truffle.language.objects.TaintNodeGen;
import org.jruby.truffle.language.objects.WriteObjectFieldNode;
import org.jruby.truffle.language.objects.WriteObjectFieldNodeGen;
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.language.parser.jruby.TranslatorDriver;
import org.jruby.truffle.language.threadlocal.ThreadLocalObject;
import org.jruby.truffle.language.translator.TranslatorDriver;
import org.jruby.truffle.language.translator.TranslatorDriver.ParserContext;
import org.jruby.util.ByteList;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -674,7 +677,12 @@ public Object evalBadBinding(DynamicObject source, DynamicObject badBinding, Not

@TruffleBoundary
private Object doEval(DynamicObject source, DynamicObject binding, String filename, boolean ownScopeForAssignments) {
final Object result = getContext().getCodeLoader().eval(ParserContext.EVAL, StringOperations.getByteListReadOnly(source), binding, ownScopeForAssignments, filename, this);
ByteList code = StringOperations.getByteListReadOnly(source);
final Source source1 = Source.fromText(code, filename);
final MaterializedFrame frame = Layouts.BINDING.getFrame(binding);
final DeclarationContext declarationContext = RubyArguments.getDeclarationContext(frame);
final RubyRootNode rootNode = getContext().getCodeLoader().parse(source1, code.getEncoding(), ParserContext.EVAL, frame, ownScopeForAssignments, this);
final Object result = getContext().getCodeLoader().execute(ParserContext.EVAL, declarationContext, rootNode, frame, RubyArguments.getSelf(frame));
assert result != null;
return result;
}
@@ -1604,11 +1612,17 @@ public boolean requireRelative(DynamicObject feature) {
final String featureString = feature.toString();
final String featurePath;

if (featureLoader.isAbsolutePath(featureString)) {
if (featureString.startsWith(SourceLoader.TRUFFLE_SCHEME) || featureString.startsWith(SourceLoader.JRUBY_SCHEME) || new File(featureString).isAbsolute()) {
featurePath = featureString;
} else {
final Source source = getContext().getCallStack().getCallerFrameIgnoringSend().getCallNode().getEncapsulatingSourceSection().getSource();
final String sourcePath = featureLoader.getSourcePath(source);
String result;
if (source.getPath() == null) {
result = source.getShortName();
} else {
result = source.getPath();
}
final String sourcePath = result;

if (sourcePath == null) {
CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ private void callSetTraceFunc(MaterializedFrame frame) {

isInTraceFunc = true;
try {
context.getCodeLoader().inlineRubyHelper(this, frame, "traceFunc.call(event, file, line, id, binding, classname)", "traceFunc", traceFunc, "event", event, "file", file, "line", line, "id", id, "binding", binding, "classname", classname);
context.getCodeLoader().inline(this, frame, "traceFunc.call(event, file, line, id, binding, classname)", "traceFunc", traceFunc, "event", event, "file", file, "line", line, "id", id, "binding", binding, "classname", classname);
} finally {
isInTraceFunc = false;
}
@@ -194,7 +194,7 @@ private void callSetTraceFunc(MaterializedFrame frame) {

isInTraceFunc = true;
try {
context.getCodeLoader().inlineRubyHelper(this, frame, callTraceFuncCode, "traceFunc", traceFunc, "event", event, "file", file, "line", line, "id", id, "binding", binding, "classname", classname);
context.getCodeLoader().inline(this, frame, callTraceFuncCode, "traceFunc", traceFunc, "event", event, "file", file, "line", line, "id", id, "binding", binding, "classname", classname);
} finally {
isInTraceFunc = false;
}
Original file line number Diff line number Diff line change
@@ -89,8 +89,8 @@
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.language.objects.SingletonClassNodeGen;
import org.jruby.truffle.language.objects.WriteInstanceVariableNode;
import org.jruby.truffle.language.translator.Translator;
import org.jruby.truffle.language.translator.TranslatorDriver.ParserContext;
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.language.parser.jruby.Translator;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.util.IdUtil;

@@ -675,7 +675,8 @@ private Object classEvalSource(DynamicObject module, DynamicObject code, String
final String space = new String(new char[line-1]).replace("\0", "\n");
Source source = Source.fromText(space + code.toString(), file);

return getContext().getCodeLoader().parseAndExecute(source, encoding, ParserContext.MODULE, module, callerFrame, true, DeclarationContext.CLASS_EVAL, this);
final RubyRootNode rootNode = getContext().getCodeLoader().parse(source, encoding, ParserContext.MODULE, callerFrame, true, this);
return getContext().getCodeLoader().execute(ParserContext.MODULE, DeclarationContext.CLASS_EVAL, rootNode, callerFrame, module);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.LoopConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreClass;
@@ -25,7 +26,6 @@
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.methods.UnsupportedOperationBehavior;

import java.math.BigInteger;

@CoreClass(name = "Integer")
@@ -127,41 +127,35 @@ public DynamicObject times(VirtualFrame frame, int n, NotProvided block) {
}

@Specialization
public Object times(VirtualFrame frame, int n, DynamicObject block) {
int count = 0;

public int times(VirtualFrame frame, int n, DynamicObject block,
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
int i = 0;
loopProfile.profileCounted(n);
try {
for (int i = 0; i < n; i++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

for (; loopProfile.inject(i < n); i++) {
yield(frame, block, i);
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
getRootNode().reportLoopCount(i);
}
}

return n;
}

@Specialization
public Object times(VirtualFrame frame, long n, DynamicObject block) {
int count = 0;

public long times(VirtualFrame frame, long n, DynamicObject block,
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
long i = 0;
loopProfile.profileCounted(n);
try {
for (long i = 0; i < n; i++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

for (; loopProfile.inject(i < n); i++) {
yield(frame, block, i);
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
getRootNode().reportLoopCount(i < Integer.MAX_VALUE ? (int) i : Integer.MAX_VALUE);
}
}

Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.translator.BodyTranslator;
import org.jruby.truffle.language.parser.jruby.BodyTranslator;
import org.jruby.util.RegexpOptions;

public class InterpolatedRegexpNode extends RubyNode {
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.methods.SymbolProcNode;
import org.jruby.truffle.language.translator.Translator;
import org.jruby.truffle.language.parser.jruby.Translator;

import java.util.Arrays;

25 changes: 25 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/debug/DebugHelpers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2013, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.debug;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameInstance;
import org.jruby.truffle.RubyContext;

public abstract class DebugHelpers {

public static Object eval(String code) {
final FrameInstance currentFrameInstance = Truffle.getRuntime().getCurrentFrame();
final Frame currentFrame = currentFrameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE, true);
return RubyContext.getLatestInstance().getCodeLoader().inline(null, currentFrame, code);
}

}
Original file line number Diff line number Diff line change
@@ -50,17 +50,21 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.backtrace.BacktraceFormatter;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.loader.SourceLoader;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.parser.ParserContext;
import org.jruby.truffle.platform.Graal;
import org.jruby.truffle.stdlib.CoverageManager;
import org.jruby.truffle.tools.SimpleShell;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;
import org.jruby.util.unsafe.UnsafeHolder;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -835,7 +839,8 @@ public boolean load(DynamicObject file, boolean wrap) {
}

try {
getContext().getCodeLoader().loadFile(StringOperations.getString(getContext(), file), this);
final RubyRootNode rootNode = getContext().getCodeLoader().parse(getContext().getSourceCache().getSource(StringOperations.getString(getContext(), file)), UTF8Encoding.INSTANCE, ParserContext.TOP_LEVEL, null, true, this);
getContext().getCodeLoader().execute(ParserContext.TOP_LEVEL, DeclarationContext.TOP_LEVEL, rootNode, null, getContext().getCoreLibrary().getMainObject());
} catch (IOException e) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(coreLibrary().loadErrorCannotLoad(file.toString(), this));
@@ -859,7 +864,39 @@ public RunJRubyRootNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public Object runJRubyRootNode() {
return getContext().getCodeLoader().execute(getContext().getInitialJRubyRootNode());
coreLibrary().getGlobalVariablesObject().define(
"$0",
StringOperations.createString(getContext(),
ByteList.create(getContext().getJRubyInterop().getArg0())));

String inputFile = getContext().getInitialJRubyRootNode().getPosition().getFile();

final Source source;

try {
if (!inputFile.equals("-e")) {
inputFile = new File(inputFile).getCanonicalPath();
}

source = getContext().getSourceCache().getSource(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
}

final RubyRootNode rootNode = getContext().getCodeLoader().parse(
source,
UTF8Encoding.INSTANCE,
ParserContext.TOP_LEVEL_FIRST,
null,
true,
null);

return getContext().getCodeLoader().execute(
ParserContext.TOP_LEVEL,
DeclarationContext.TOP_LEVEL,
rootNode,
null,
coreLibrary().getMainObject());
}
}

Loading

0 comments on commit 49cb6c7

Please sign in to comment.