Skip to content

Commit

Permalink
Showing 25 changed files with 197 additions and 113 deletions.
4 changes: 2 additions & 2 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -45,9 +45,9 @@
jar 'com.github.jnr:jnr-enxio:0.9', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-unixsocket:0.8', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.15', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.18-SNAPSHOT', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-constants:0.9.0', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-ffi:2.0.4-SNAPSHOT'
jar 'com.github.jnr:jnr-ffi:2.0.4'
jar 'com.github.jnr:jffi:${jffi.version}'
jar 'com.github.jnr:jffi:${jffi.version}:native'

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

unless Truffle.graal?
it "returns nil" do
Truffle::Primitive.assert_constant(14 + 2).should be_nil
it "returns the value of the argument" do
Truffle::Primitive.assert_constant(14 + 2).should == 16
end
end

8 changes: 4 additions & 4 deletions test/truffle/pe/core/array_pe.rb
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "[3, 1, 2][1]"
example "[3, 1, 2][1]", 1

example "[3, 1, 2].sort[1]"
example "[3, 1, 2].sort[1]", 2

# why does this fail but the next one work?
tagged_example "[14].pack('C').getbyte(0)"
tagged_example "[14].pack('C').getbyte(0)", 14

example "[14].pack('C').getbyte(0) * 2"
example "[14].pack('C').getbyte(0) * 2", 28
28 changes: 26 additions & 2 deletions test/truffle/pe/core/binding_pe.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
# Copyright (c) 2015 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

example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x)"
# why do the tagged_example fail? identity of boxing?

# Kernel#binding
tagged_example "x = 14; binding.local_variable_get(:x)", 14
example "x = 14; binding.local_variable_get(:x) * 2", 28

# Proc#binding
tagged_example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x)", 14
example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x) * 2", 28

# set + get
tagged_example "b = binding; b.local_variable_set(:x, 14); b.local_variable_get(:x)", 14
example "b = binding; b.local_variable_set(:x, 14); b.local_variable_get(:x) * 2", 28

# get (2 levels)
tagged_example "x = 14; y = nil; 1.times { y = binding.local_variable_get(:x) }; y", 14
example "x = 14; y = nil; 1.times { y = binding.local_variable_get(:x) }; y * 2", 28

# set (2 levels)
tagged_example "x = 14; 1.times { binding.local_variable_set(:x, 15) }; x", 15
example "x = 14; 1.times { binding.local_variable_set(:x, 15) }; x * 2", 30

# get + set (2 levels)
tagged_example "x = 14; y = nil; 1.times { binding.local_variable_set(:x, 15); y = binding.local_variable_get(:x) }; y", 15
example "x = 14; y = nil; 1.times { binding.local_variable_set(:x, 15); y = binding.local_variable_get(:x) }; y * 2", 30
8 changes: 4 additions & 4 deletions test/truffle/pe/core/eval_pe.rb
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "eval('14')"
example "eval('14')", 14

example "eval('14 + 2')"
example "eval('14 + 2')", 16

example "eval('[1, 2, 3]')[1]"
example "eval('[1, 2, 3]')[1]", 2

example "eval([1, 2, 3].inspect)[1]"
example "eval([1, 2, 3].inspect)[1]", 2

counter_example "eval(rand.to_s)"
20 changes: 10 additions & 10 deletions test/truffle/pe/core/fixnum_pe.rb
Original file line number Diff line number Diff line change
@@ -6,21 +6,21 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "14"
example "14", 14

example "14 + 2"
counter_example "14 + 0xfffffffffffffffffffffffffffffff"
example "14 + 2.0"
example "14 + 2", 16
tagged_counter_example "14 + 0xfffffffffffffffffffffffffffffff" # Graal error
example "14 + 2.0", 16.0
counter_example "14 + rand"

example "14 * 2"
example "14 * 2", 28
counter_example "14 * 0xfffffffffffffffffffffffffffffff"
example "14 * 2.0"
example "14 * 2.0", 28.0
counter_example "14 * rand"

example "14 / 2"
example "14 / 0xfffffffffffffffffffffffffffffff"
example "14 / 2.0"
example "14 / 2", 7
example "14 / 0xfffffffffffffffffffffffffffffff", 0
example "14 / 2.0", 7.0
counter_example "14 / rand"

example "14 <=> 2"
example "14 <=> 2", 1
14 changes: 7 additions & 7 deletions test/truffle/pe/core/float_pe.rb
Original file line number Diff line number Diff line change
@@ -6,19 +6,19 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "14.2"
example "14.2", 14.2

example "14.0 + 2"
example "14.0 + 2", 16.0
counter_example "14.0 + 0xfffffffffffffffffffffffffffffff"
example "14.0 + 2.0"
example "14.0 + 2.0", 16.0
counter_example "14.0 + rand"

example "14.0 * 2"
example "14.0 * 2", 28.0
counter_example "14.0 * 0xfffffffffffffffffffffffffffffff"
example "14.0 * 2.0"
example "14.0 * 2.0", 28.0
counter_example "14.0 * rand"

example "14.0 / 2"
example "14.0 / 2", 7.0
counter_example "14.0 / 0xfffffffffffffffffffffffffffffff"
example "14.0 / 2.0"
example "14.0 / 2.0", 7.0
counter_example "14.0 / rand"
35 changes: 35 additions & 0 deletions test/truffle/pe/core/frozen_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2015 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


example "true.frozen?"

example "false.frozen?"

# int
example "3.frozen?"

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

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

# float
example "3.5.frozen?"

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

example ":symbol.frozen?"

example "nil.frozen?"

example "'abc'.frozen?"

example "'abc'.freeze.frozen?"
4 changes: 2 additions & 2 deletions test/truffle/pe/core/hash_pe.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,6 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "({a: 0, b: 1, c: 2})[:b]"
example "({a: 0, b: 1, c: 2})[:b]", 1

example "({a: 0, b: 1, c: 2}).map{ |k, v| v }[0]"
example "({a: 0, b: 1, c: 2}).map{ |k, v| v }[0]", 0
9 changes: 2 additions & 7 deletions test/truffle/pe/core/method_pe.rb
Original file line number Diff line number Diff line change
@@ -6,10 +6,5 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "1.method(:abs).call"
example "1.method(:abs).unbind.bind(-2).call"

# These 3 are not constant currently since they produce new objects
tagged_example "1.method(:abs)"
tagged_example "1.method(:abs).unbind"
tagged_example "1.method(:abs).unbind.bind(-2)"
example "1.method(:abs).call", 1
example "1.method(:abs).unbind.bind(-2).call", 2
10 changes: 5 additions & 5 deletions test/truffle/pe/core/objectid_pe.rb
Original file line number Diff line number Diff line change
@@ -6,12 +6,12 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "nil.object_id"
example "nil.object_id", 4

example "true.object_id"
example "true.object_id", 2

example "false.object_id"
example "false.object_id", 0

example "14.object_id"
example "14.object_id", 29

example "(14 + 2).object_id"
example "(14 + 2).object_id", 33
6 changes: 3 additions & 3 deletions test/truffle/pe/core/send_pe.rb
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "14.send(:*, 2)"
example "14.send(:*, 2)", 28

example "14.send('*', 2)"
example "14.send('*', 2)", 28

example "14.send((')'.ord + 1).chr, 2)"
example "14.send((')'.ord + 1).chr, 2)", 28
6 changes: 3 additions & 3 deletions test/truffle/pe/core/symbol_pe.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,6 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example ":foo"
example ":foo == :foo"
example ":foo != :bar"
example ":foo", :foo
example ":foo == :foo", true
example ":foo != :bar", true
4 changes: 2 additions & 2 deletions test/truffle/pe/core/truefalse_pe.rb
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "true"
example "false"
example "true", true
example "false", false
2 changes: 1 addition & 1 deletion test/truffle/pe/language/closures_pe.rb
Original file line number Diff line number Diff line change
@@ -14,4 +14,4 @@ def self.yielder

end

example "x = 14; ClosureFixtures.yielder { x } + 2"
example "x = 14; ClosureFixtures.yielder { x } + 2", 16
14 changes: 7 additions & 7 deletions test/truffle/pe/language/constant_pe.rb
Original file line number Diff line number Diff line change
@@ -48,14 +48,14 @@ def self.const_missing(const)
end
end

example "ConstantFixtures.get_existing"
example "ConstantFixtures.get"
example "ConstantFixtures.get_const_get(:A)"
example "ConstantFixtures.get_existing", Proc
example "ConstantFixtures.get", 1
example "ConstantFixtures.get_const_get(:A)", 1

# Internal Graal compiler error
tagged_example "ConstantFixtures.get_const_get('A')"
tagged_example "ConstantFixtures.get_const_get('A')", 1

example "ConstantFixtures::Nested.get_nested"
example "ConstantFixtures::Child.get_inherited"
example "ConstantFixtures::Nested.get_nested", 1
example "ConstantFixtures::Child.get_inherited", 2

example "ConstantFixtures::ConstMissing.get_missing"
example "ConstantFixtures::ConstMissing.get_missing", :NO_SUCH_NAMED_CONSTANT
2 changes: 1 addition & 1 deletion test/truffle/pe/language/controlflow_pe.rb
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

example "rand < 0.5 ? 14 : 16 - 2"
example "rand < 0.5 ? 14 : 16 - 2", 14
counter_example "rand < 0.5 ? 14 : 16 + 2"
8 changes: 4 additions & 4 deletions test/truffle/pe/language/ivar_pe.rb
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ def reset_b(b)
end
end

example "IVarFixtures::Foo.new(1,2).a"
example "IVarFixtures::Foo.new(1,2).b"
example "IVarFixtures::Foo.new(1,2).a", 1
example "IVarFixtures::Foo.new(1,2).b", 2

example "IVarFixtures::Foo.new(1,2).reset_b(42).b"
example "IVarFixtures::Foo.new(1,2).reset_b([]).b.empty?"
example "IVarFixtures::Foo.new(1,2).reset_b(42).b", 42
example "IVarFixtures::Foo.new(1,2).reset_b([]).b.empty?", true
6 changes: 3 additions & 3 deletions test/truffle/pe/language/metaprogramming_pe.rb
Original file line number Diff line number Diff line change
@@ -26,6 +26,6 @@ def existing_method(a)

end

example "MetaprogrammingFixtures::MethodMissing.new.does_not_exist"
example "MetaprogrammingFixtures::ClassWithExistingMethod.new.respond_to?(:existing_method)"
example "MetaprogrammingFixtures::ClassWithExistingMethod.new.send(:existing_method, 14)"
example "MetaprogrammingFixtures::MethodMissing.new.does_not_exist", 14
example "MetaprogrammingFixtures::ClassWithExistingMethod.new.respond_to?(:existing_method)", true
example "MetaprogrammingFixtures::ClassWithExistingMethod.new.send(:existing_method, 15)", 15
8 changes: 4 additions & 4 deletions test/truffle/pe/language/super_pe.rb
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@ def call_zsuper(n)
INSTANCE = Child.new
end

example "SuperFixtures::INSTANCE.call_super(42)"
example "SuperFixtures::INSTANCE.call_zsuper(24)"
example "SuperFixtures::INSTANCE.call_super(42)", 84
example "SuperFixtures::INSTANCE.call_zsuper(24)", 72

example "SuperFixtures::Child.new.call_super(42)"
example "SuperFixtures::Child.new.call_zsuper(24)"
example "SuperFixtures::Child.new.call_super(42)", 84
example "SuperFixtures::Child.new.call_zsuper(24)", 72
2 changes: 1 addition & 1 deletion test/truffle/pe/macro/pushing_pixels_pe.rb
Original file line number Diff line number Diff line change
@@ -35,4 +35,4 @@ def method_missing(method, *args)

end

example "PushingPixelsFixtures::Bar.new.foo(14, 8, 6)"
example "PushingPixelsFixtures::Bar.new.foo(14, 8, 6)", 22
73 changes: 45 additions & 28 deletions test/truffle/pe/pe.rb
Original file line number Diff line number Diff line change
@@ -28,41 +28,52 @@

TIMEOUT = 10

TIMEOUT = 10

EXAMPLES = []

def example(code, expected_constant=true, tagged=false)
EXAMPLES << [code, expected_constant, tagged]
def example(code, expected_value, expected_constant=true, tagged=false)
EXAMPLES << [code, expected_value, expected_constant, tagged]
end

def tagged_example(code, expected_value)
example(code, expected_value, true, true)
end

def counter_example(code)
example(code, false, false)
example(code, nil, false, false)
end

def tagged_example(code)
example(code, false, true)
def tagged_counter_example(code)
example(code, nil, false, true)
end

example "14"
example "14", 14
counter_example "rand"

require_relative 'language/controlflow_pe.rb'
require_relative 'language/closures_pe.rb'
require_relative 'language/constant_pe.rb'
require_relative 'language/ivar_pe.rb'
require_relative 'language/metaprogramming_pe.rb'
require_relative 'language/super_pe.rb'
require_relative 'core/truefalse_pe.rb'
require_relative 'core/fixnum_pe.rb'
require_relative 'core/float_pe.rb'
require_relative 'core/symbol_pe.rb'
require_relative 'core/method_pe.rb'
require_relative 'core/array_pe.rb'
require_relative 'core/hash_pe.rb'
require_relative 'core/eval_pe.rb'
require_relative 'core/send_pe.rb'
require_relative 'core/objectid_pe.rb'
require_relative 'core/binding_pe.rb'
require_relative 'macro/pushing_pixels_pe.rb'
if ARGV.first
require File.expand_path(ARGV.first)
else
require_relative 'language/controlflow_pe.rb'
require_relative 'language/closures_pe.rb'
require_relative 'language/constant_pe.rb'
require_relative 'language/ivar_pe.rb'
require_relative 'language/metaprogramming_pe.rb'
require_relative 'language/super_pe.rb'
require_relative 'core/truefalse_pe.rb'
require_relative 'core/fixnum_pe.rb'
require_relative 'core/float_pe.rb'
require_relative 'core/symbol_pe.rb'
require_relative 'core/method_pe.rb'
require_relative 'core/array_pe.rb'
require_relative 'core/hash_pe.rb'
require_relative 'core/eval_pe.rb'
require_relative 'core/send_pe.rb'
require_relative 'core/objectid_pe.rb'
require_relative 'core/binding_pe.rb'
require_relative 'core/frozen_pe.rb'
require_relative 'macro/pushing_pixels_pe.rb'
end

tested = 0
failed = 0
@@ -74,15 +85,16 @@ def report(status, code, message = nil)
puts message ? format(format_str + "\n %s", status, code, message) : format('%14s: %s', status, code)
end

EXAMPLES.each do |code, expected_constant, tagged|
EXAMPLES.each do |code, expected_value, expected_constant, tagged|
next if tagged

finished = false

test_thread = Thread.new do
begin
tested += 1
eval "loop { Truffle::Primitive.assert_constant #{code}; Truffle::Primitive.assert_not_compiled; Thread.pass }"
value = nil
eval "loop { value = Truffle::Primitive.assert_constant begin; #{code}; end; Truffle::Primitive.assert_not_compiled; Thread.pass }"
rescue RubyTruffleError => e
if e.message.include? 'Truffle::Primitive.assert_not_compiled'
constant = true
@@ -101,11 +113,16 @@ def report(status, code, message = nil)
report 'FAILED', code, "wasn't constant"
failed += 1
else
report 'OK', code
if value == expected_value
report 'OK', code
else
report 'INCORRECT', code, "was: #{value.inspect} and not: #{expected_value.inspect}"
failed += 1
end
end
else
if constant
report 'QUERY', code, "wasn't supposed to be constant but it was"
report 'QUERY', code, "wasn't supposed to be constant but it was (#{value.inspect})"
failed += 1
else
report 'OK (counter)', code
3 changes: 2 additions & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -340,7 +340,8 @@ def test(*args)
end

def test_pe(*args)
run('--graal', *args, 'test/truffle/pe/pe.rb')
file = args.pop if args.last and File.exist?(args.last)
run('--graal', *args, 'test/truffle/pe/pe.rb', *file)
end
private :test_pe

Original file line number Diff line number Diff line change
@@ -52,6 +52,16 @@ public static DynamicObject createBinding(RubyContext context, MaterializedFrame
return Layouts.BINDING.createBinding(context.getCoreLibrary().getBindingFactory(), bindingFrame);
}

public static FrameDescriptor getFrameDescriptor(DynamicObject binding) {
assert RubyGuards.isRubyBinding(binding);
return Layouts.BINDING.getFrame(binding).getFrameDescriptor();
}

public static MaterializedFrame getDeclarationFrame(DynamicObject binding) {
assert RubyGuards.isRubyBinding(binding);
return RubyArguments.getDeclarationFrame(Layouts.BINDING.getFrame(binding).getArguments());
}

protected static class FrameSlotAndDepth {
private final FrameSlot slot;
private final int depth;
@@ -62,11 +72,6 @@ public FrameSlotAndDepth(FrameSlot slot, int depth) {
}
}

public static FrameDescriptor getFrameDescriptor(DynamicObject binding) {
assert RubyGuards.isRubyBinding(binding);
return Layouts.BINDING.getFrame(binding).getFrameDescriptor();
}

public static FrameSlotAndDepth findFrameSlotOrNull(DynamicObject binding, DynamicObject symbol) {
assert RubyGuards.isRubyBinding(binding);
assert RubyGuards.isRubySymbol(symbol);
@@ -131,11 +136,11 @@ public LocalVariableGetNode(RubyContext context, SourceSection sourceSection) {
"isRubySymbol(symbol)",
"symbol == cachedSymbol",
"!isLastLine(cachedSymbol)",
"getFrameDescriptor(binding) == cachedFrameDescriptor",
"compatibleFrames(binding, cachedBinding)",
}, limit = "getCacheLimit()")
public Object localVariableGetCached(DynamicObject binding, DynamicObject symbol,
@Cached("symbol") DynamicObject cachedSymbol,
@Cached("getFrameDescriptor(binding)") FrameDescriptor cachedFrameDescriptor,
@Cached("binding") DynamicObject cachedBinding,
@Cached("findFrameSlotOrNull(binding, symbol)") FrameSlotAndDepth cachedFrameSlot,
@Cached("createReadNode(cachedFrameSlot)") ReadFrameSlotNode readLocalVariableNode) {
if (cachedFrameSlot == null) {
@@ -177,6 +182,14 @@ public Object localVariableGetLastLine(DynamicObject binding, DynamicObject symb
}
}

protected boolean compatibleFrames(DynamicObject binding1, DynamicObject binding2) {
final FrameDescriptor fd1 = getFrameDescriptor(binding1);
final FrameDescriptor fd2 = getFrameDescriptor(binding2);

return ((fd1 == fd2) || (fd1.getSize() == 0 && fd2.getSize() == 0)) &&
getDeclarationFrame(binding1).getFrameDescriptor() == getDeclarationFrame(binding2).getFrameDescriptor();
}

protected ReadFrameSlotNode createReadNode(FrameSlotAndDepth frameSlot) {
if (frameSlot == null) {
return null;
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
@@ -29,7 +28,7 @@ public AssertConstantNode(RubyContext context, SourceSection sourceSection) {
private static volatile boolean[] sideEffect;

@Specialization
public DynamicObject assertCompilationConstant(Object value) {
public Object assertCompilationConstant(Object value) {
final boolean[] compilationConstant = new boolean[]{CompilerDirectives.isCompilationConstant(value)};

sideEffect = compilationConstant;
@@ -39,7 +38,7 @@ public DynamicObject assertCompilationConstant(Object value) {
throw new RaiseException(getContext().getCoreLibrary().internalError("Value in Truffle::Primitive.assert_constant was not constant", this));
}

return nil();
return value;
}

}

0 comments on commit 6d25089

Please sign in to comment.