Skip to content

Commit

Permalink
Showing 5 changed files with 70 additions and 60 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.15</version>
<version>3.0.18-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>jnr-ffi</artifactId>
@@ -158,7 +158,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-ffi</artifactId>
<version>2.0.4-SNAPSHOT</version>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
22 changes: 11 additions & 11 deletions test/truffle/pe/core/frozen_pe.rb
Original file line number Diff line number Diff line change
@@ -7,29 +7,29 @@
# GNU Lesser General Public License version 2.1


example "true.frozen?"
example "true.frozen?", true

example "false.frozen?"
example "false.frozen?", true

# int
example "3.frozen?"
example "3.frozen?", true

# long
example "(2**62).frozen?"
example "(2**62).frozen?", true

# Bignum
example "(10 ** 100).frozen?"
example "(10 ** 100).frozen?", true

# float
example "3.5.frozen?"
example "3.5.frozen?", true

# double
example "(2**62).to_f.frozen?"
example "(2**62).to_f.frozen?", true

example ":symbol.frozen?"
example ":symbol.frozen?", true

example "nil.frozen?"
example "nil.frozen?", true

example "'abc'.frozen?"
example "'abc'.frozen?", false

example "'abc'.freeze.frozen?"
example "'abc'.freeze.frozen?", true
51 changes: 12 additions & 39 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -9,32 +9,29 @@
*/
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.ProbeNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.source.SourceSection;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;

import org.jcodings.specific.UTF8Encoding;
import org.jruby.RubyString;
import org.jruby.truffle.nodes.instrument.RubyWrapperNode;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.sockets.NativeSockets;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.ProbeNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.source.SourceSection;

@TypeSystemReference(RubyTypes.class)
@ImportStatic(RubyGuards.class)
public abstract class RubyNode extends Node {
@@ -215,31 +212,7 @@ public MemoryManager getMemoryManager() {
// ruby() helper

protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupFrame(frame, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), evalFrame);
return getContext().eval(expression, binding, true, "inline-ruby", this);
}

private MaterializedFrame setupFrame(VirtualFrame frame, Object... arguments) {
CompilerDirectives.transferToInterpreter();
final MaterializedFrame evalFrame = Truffle.getRuntime().createMaterializedFrame(
RubyArguments.pack(
RubyArguments.getMethod(frame.getArguments()),
null,
RubyArguments.getSelf(frame.getArguments()),
null,
new Object[] {}),
new FrameDescriptor(nil()));

if (arguments.length % 2 == 1) {
throw new UnsupportedOperationException("odd number of name-value pairs for arguments");
}

for (int n = 0; n < arguments.length; n += 2) {
evalFrame.setObject(evalFrame.getFrameDescriptor().findOrAddFrameSlot(arguments[n]), arguments[n + 1]);
}

return evalFrame;
return getContext().inlineRubyHelper(this, frame, expression, arguments);
}

}
Original file line number Diff line number Diff line change
@@ -44,8 +44,7 @@ public Object getName() {
@Specialization(
guards = {
"location != null",
"object.getShape() == cachedShape",
"location.canSet(object, value)"
"object.getShape() == cachedShape"
},
assumptions = { "newArray(cachedShape.getValidAssumption(), validLocation)" },
limit = "getCacheLimit()")
@@ -55,21 +54,17 @@ public void writeExistingField(DynamicObject object, Object value,
@Cached("createAssumption()") Assumption validLocation) {
try {
location.set(object, value, cachedShape);
} catch (IncompatibleLocationException e) {
} catch (IncompatibleLocationException | FinalLocationException e) {
// remove this entry
validLocation.invalidate();
execute(object, value);
} catch (FinalLocationException e) {
throw new UnsupportedOperationException("write to final location?", e);
}
}

@Specialization(
guards = {
"!hasField",
"newShape != null", // workaround for DSL bug
"object.getShape() == oldShape",
"location.canSet(object, value)" },
"object.getShape() == oldShape" },
assumptions = { "newArray(oldShape.getValidAssumption(), newShape.getValidAssumption(), validLocation)" },
limit = "getCacheLimit()")
public void writeNewField(DynamicObject object, Object value,
42 changes: 42 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -11,20 +11,26 @@

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
import com.oracle.truffle.api.instrument.Probe;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.tools.CoverageTracker;

import jnr.ffi.LibraryLoader;
import jnr.ffi.Runtime;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
@@ -213,6 +219,42 @@ public Object send(Object object, String methodName, DynamicObject block, Object
RubyArguments.pack(method, method.getDeclarationFrame(), object, block, arguments));
}

/* For debugging in Java. */
public static Object debugEval(String code) {
CompilerAsserts.neverPartOfCompilation();
final FrameInstance currentFrameInstance = Truffle.getRuntime().getCurrentFrame();
final Frame currentFrame = currentFrameInstance.getFrame(FrameAccess.MATERIALIZE, true);
return getLatestInstance().inlineRubyHelper(null, currentFrame, code);
}

public Object inlineRubyHelper(Node currentNode, Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupInlineRubyFrame(frame, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getCoreLibrary().getBindingFactory(), evalFrame);
return eval(expression, binding, true, "inline-ruby", currentNode);
}

private MaterializedFrame setupInlineRubyFrame(Frame frame, Object... arguments) {
CompilerDirectives.transferToInterpreter();
final MaterializedFrame evalFrame = Truffle.getRuntime().createMaterializedFrame(
RubyArguments.pack(
RubyArguments.getMethod(frame.getArguments()),
null,
RubyArguments.getSelf(frame.getArguments()),
null,
new Object[] {}),
new FrameDescriptor(frame.getFrameDescriptor().getDefaultValue()));

if (arguments.length % 2 == 1) {
throw new UnsupportedOperationException("odd number of name-value pairs for arguments");
}

for (int n = 0; n < arguments.length; n += 2) {
evalFrame.setObject(evalFrame.getFrameDescriptor().findOrAddFrameSlot(arguments[n]), arguments[n + 1]);
}

return evalFrame;
}

@Override
public void initialize() {
// Give the core library manager a chance to tweak some of those methods

0 comments on commit d790d05

Please sign in to comment.