Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: baeb61d6ac61
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ef2541d954c3
Choose a head ref
  • 5 commits
  • 17 files changed
  • 1 contributor

Commits on Dec 7, 2015

  1. Copy the full SHA
    1309c65 View commit details
  2. Copy the full SHA
    82c24f8 View commit details
  3. Copy the full SHA
    4c5c6b9 View commit details
  4. Copy the full SHA
    390162e View commit details
  5. Copy the full SHA
    ef2541d View commit details
3 changes: 0 additions & 3 deletions core/src/main/java/org/jruby/util/Memo.java
Original file line number Diff line number Diff line change
@@ -9,9 +9,6 @@
*/
package org.jruby.util;

/**
* @deprecated no longer used, should get removed
*/
public class Memo<T> {

private T value;
33 changes: 18 additions & 15 deletions spec/truffle/specs/truffle/attachments/attach_spec.rb
Original file line number Diff line number Diff line change
@@ -17,60 +17,63 @@ def fixture
x
end

after :all do
[14, 15, 16].each do |line|
Truffle::Attachments.detach __FILE__, line
end
before :each do
@attachments = []
end

it "returns nil" do
Truffle::Attachments.attach(__FILE__, 14){}.should be_nil
after :each do
@attachments.each(&:detach)
end

it "installs a block to be run on a line" do
scratch = [false]
Truffle::Attachments.attach __FILE__, 14 do

@attachments << Truffle::Attachments.attach(__FILE__, 14) do
scratch[0] = true
end

fixture.should == 14
scratch[0].should be_true
end

it "allows multiple blocks to be installed on the same line and runs them in an indeterminate order" do
it "allows multiple blocks to be installed on the same line and runs both of them" do
scratch = []
Truffle::Attachments.attach __FILE__, 14 do

@attachments << Truffle::Attachments.attach(__FILE__, 14) do
scratch << 1
end
Truffle::Attachments.attach __FILE__, 14 do

@attachments << Truffle::Attachments.attach(__FILE__, 14) do
scratch << 2
end

fixture.should == 14
scratch.sort.should == [1, 2]
end

it "supplies a Binding to the block" do
Truffle::Attachments.attach __FILE__, 14 do |binding|
@attachments << Truffle::Attachments.attach(__FILE__, 14) do |binding|
binding.should be_kind_of(Binding)
end
fixture.should == 14
end

it "allows read access to local variables in the block" do
Truffle::Attachments.attach __FILE__, 15 do |binding|
@attachments << Truffle::Attachments.attach(__FILE__, 15) do |binding|
binding.local_variable_get(:x).should == 14
end
fixture.should == 14
end

it "allows write access to local variables in the block" do
Truffle::Attachments.attach __FILE__, 15 do |binding|
@attachments << Truffle::Attachments.attach(__FILE__, 15) do |binding|
binding.local_variable_set(:x, 100)
end
fixture.should == 100
end

it "runs the block before running the line" do
Truffle::Attachments.attach __FILE__, 16 do |binding|
@attachments << Truffle::Attachments.attach(__FILE__, 16) do |binding|
binding.local_variable_get(:x).should == 14
binding.local_variable_get(:y).should == 15
end
54 changes: 0 additions & 54 deletions spec/truffle/specs/truffle/attachments/detach_spec.rb

This file was deleted.

13 changes: 10 additions & 3 deletions spec/truffle/specs/truffle/binding_of_caller_spec.rb
Original file line number Diff line number Diff line change
@@ -9,19 +9,26 @@
require_relative '../../../ruby/spec_helper'

describe "Truffle.binding_of_caller" do

def binding_of_caller
Truffle.binding_of_caller
end

#it "returns nil if there is no caller"
#end

it "returns a Binding" do
Truffle.binding_of_caller.should be_kind_of(Binding)
binding_of_caller.should be_kind_of(Binding)
end

it "gives read access to local variables at the call site" do
x = 14
Truffle.binding_of_caller.local_variable_get(:x).should == 14
binding_of_caller.local_variable_get(:x).should == 14
end

it "gives write access to local variables at the call site" do
x = 2
Truffle.binding_of_caller.local_variable_set(:x, 14)
binding_of_caller.local_variable_set(:x, 14)
x.should == 14
end

2 changes: 1 addition & 1 deletion spec/truffle/specs/truffle/cext/load_extconf_spec.rb
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

it "raises a RuntimeError" do
lambda {
Truffle::CExt.load_extconf File.expand_path('fixtures/foo/ext/foo/extconf.rb', __FILE__)
Truffle::CExt.load_extconf File.expand_path('fixtures/foo/ext/foo/extconf.rb', File.dirname(__FILE__))
}.should raise_error(RuntimeError)
end

4 changes: 2 additions & 2 deletions spec/truffle/specs/truffle/primitive/coverage_result_spec.rb
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@

describe "Truffle::Primitive.coverage_result" do

it "returns nil" do
Truffle::Primitive.coverage_result.should be_nil
it "returns an empty hash" do
Truffle::Primitive.coverage_result.should == {}
end

it "needs to be reviewed for spec completeness"
11 changes: 9 additions & 2 deletions spec/truffle/specs/truffle/source_of_caller_spec.rb
Original file line number Diff line number Diff line change
@@ -9,13 +9,20 @@
require_relative '../../../ruby/spec_helper'

describe "Truffle.source_of_caller" do

def source_of_caller
Truffle.source_of_caller
end

#it "returns nil if there is no caller"
#end

it "returns a String" do
Truffle.source_of_caller.should be_kind_of(String)
source_of_caller.should be_kind_of(String)
end

it "returns the name of the file at the call site" do
Truffle.source_of_caller.should == __FILE__
source_of_caller.should == __FILE__
end

it "works through #send" do
3 changes: 0 additions & 3 deletions spec/truffle/tags/truffle/attachments/attach_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/truffle/binding_of_caller_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/truffle/cext/load_extconf_tags.txt

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/truffle/source_of_caller_tags.txt

This file was deleted.

2 changes: 1 addition & 1 deletion spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ class MSpecScript
set :target, File.expand_path("../../../bin/jruby#{windows? ? '.bat' : ''}", __FILE__)

if ARGV[-2..-1] != %w[-t ruby] # No flags for MRI
set :flags, %w[-X+T -J-ea -J-esa -J-Xmx2G]
set :flags, %w[-X+T -J-ea -J-esa -J-Xmx2G -Xtruffle.coverage=true]
end

set :language, [
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrument.Instrument;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.Source;
@@ -63,6 +64,7 @@ public BindingOfCallerNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public DynamicObject bindingOfCaller() {
/*
@@ -86,6 +88,10 @@ public MaterializedFrame visitFrame(FrameInstance frameInstance) {

});

if (frame == null) {
return nil();
}

return BindingNodes.createBinding(getContext(), frame);
}

@@ -98,6 +104,7 @@ public SourceOfCallerNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public DynamicObject sourceOfCaller() {
final Memo<Integer> frameCount = new Memo<>(0);
@@ -116,6 +123,10 @@ public String visitFrame(FrameInstance frameInstance) {

});

if (source == null) {
return nil();
}

return createString(StringOperations.encodeByteList(source, UTF8Encoding.INSTANCE));
}

@@ -346,23 +357,23 @@ public AttachNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization(guards = "isRubyString(file)")
public DynamicObject attach(DynamicObject file, int line, DynamicObject block) {
getContext().getAttachmentsManager().attach(file.toString(), line, block);
return getContext().getCoreLibrary().getNilObject();
return getContext().createHandle(getContext().getAttachmentsManager().attach(file.toString(), line, block));
}

}

@CoreMethod(names = "detach", onSingleton = true, required = 2)
@CoreMethod(names = "detach", onSingleton = true, required = 1)
public abstract static class DetachNode extends CoreMethodArrayArgumentsNode {

public DetachNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization(guards = "isRubyString(file)")
public DynamicObject detach(DynamicObject file, int line) {
getContext().getAttachmentsManager().detach(file.toString(), line);
@Specialization(guards = "isHandle(handle)")
public DynamicObject detach(DynamicObject handle) {
final Instrument instrument = (Instrument) Layouts.HANDLE.getObject(handle);
instrument.dispose();
return getContext().getCoreLibrary().getNilObject();
}

Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public AttachmentsManager(RubyContext context) {
lineToProbesMap.install();
}

public synchronized void attach(String file, int line, final DynamicObject block) {
public synchronized Instrument attach(String file, int line, final DynamicObject block) {
final Instrument instrument = Instrument.create(new StandardInstrumentListener() {

@Override
@@ -86,25 +86,11 @@ public void returnExceptional(Probe probe, Node node, VirtualFrame virtualFrame,
for (Probe probe : lineToProbesMap.findProbes(lineLocation)) {
if (probe.isTaggedAs(StandardSyntaxTag.STATEMENT)) {
probe.attach(instrument);
return;
return instrument;
}
}

throw new RuntimeException("couldn't find a statement!");
}

public synchronized void detach(String file, int line) {
final Source source = context.getSourceCache().getBestSourceFuzzily(file);

final LineLocation lineLocation = source.createLineLocation(line);

final List<Instrument> instruments = attachments.remove(lineLocation);

if (instruments != null) {
for (Instrument instrument : instruments) {
instrument.dispose();
}
}
}

}
30 changes: 17 additions & 13 deletions truffle/src/main/ruby/core/truffle/attachments.rb
Original file line number Diff line number Diff line change
@@ -15,30 +15,34 @@ module Attachments

# Attach a block to be called each time before a given line in a given file
# is executed, passing the binding at that point to the block.
# @return [nil]
# @return [Attachment]
#
# # Examples
#
# ```
# Truffle::Attachments.attach __FILE__, 21 do |binding|
# attachment = Truffle::Attachments.attach(__FILE__, 21) do |binding|
# # Double the value of local variable foo before this line runs
# binding.local_variable_set(:foo, binding.local_variable_get(:foo) * 2)
# end
# ...
# attachment.detach
# ```
def self.attach(file, line, &block)
Truffle::Primitive.attach file, line, &block
Attachment.new(Truffle::Primitive.attach(file, line, &block))
end

# Detach all blocks at a given line in a given file.
# @return [nil]
#
# # Examples
#
# ```
# Truffle::Attachments.detach __FILE__, 21
# ```
def self.detach(file, line)
Truffle::Primitive.detach file, line
# Represents a block which has been installed.
class Attachment

def initialize(handle)
@handle = handle
end

# Detach the code which was attached.
def detach
Truffle::Primitive.detach @handle
end

end

end