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: 507558d10af5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 87dc89be7186
Choose a head ref
  • 7 commits
  • 8 files changed
  • 1 contributor

Commits on Nov 26, 2015

  1. Copy the full SHA
    11d6dc4 View commit details
  2. Copy the full SHA
    e9f7197 View commit details
  3. Copy the full SHA
    a50562c View commit details
  4. Revert "[Truffle] Do not confuce Random with OpenSSL::Random"

    * This reverts commit 0ab1c79.
    * defined?(A::B) is fixed and false if either A or B is not defined.
    eregon committed Nov 26, 2015
    Copy the full SHA
    aa41d54 View commit details
  5. Copy the full SHA
    3265477 View commit details
  6. Copy the full SHA
    b38348b View commit details
  7. Copy the full SHA
    87dc89b View commit details
Original file line number Diff line number Diff line change
@@ -56,8 +56,7 @@ module SecureRandom
def self.random_bytes(n=nil)
n ||= 16

# TODO (pitr 04-Oct-2015): pending PR https://github.com/rubysl/rubysl-securerandom/pull/1
if defined?(OpenSSL::Random) && OpenSSL::Random != Random
if defined? OpenSSL::Random
@pid = 0 if !defined?(@pid)
pid = $$
if @pid != pid
48 changes: 12 additions & 36 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -1472,40 +1472,24 @@ public double rand(NotProvided max) {
return getContext().getRandom().nextDouble();
}

@Specialization(guards = "isZero(max)")
@Specialization(guards = "max == 0")
public double randZero(int max) {
return getContext().getRandom().nextDouble();
}

@Specialization(guards = "isNonZero(max)")
@Specialization(guards = "max != 0")
public int randNonZero(int max) {
return getContext().getRandom().nextInt(max);
}

@Specialization(guards = "isZero(max)")
@Specialization(guards = "max == 0")
public double randZero(long max) {
return getContext().getRandom().nextDouble();
}

@Specialization(guards = "isNonZero(max)")
@Specialization(guards = "max != 0")
public long randNonZero(long max) {
return getContext().getRandom().nextLong() % max;
}

protected boolean isZero(int max) {
return max == 0;
}

protected boolean isNonZero(int max) {
return max != 0;
}

protected boolean isZero(long max) {
return max == 0;
}

protected boolean isNonZero(long max) {
return max != 0;
return getContext().getRandom().nextLong(max);
}

}
@@ -1531,30 +1515,17 @@ public boolean require(DynamicObject featureString) {
final String feature = featureString.toString();

// Pysch loads either the jar or the so - we need to intercept

if (feature.equals("psych.so") && RubyCallStack.getCallerFrame(getContext()).getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith("psych.rb")) {
if (feature.equals("psych.so") && callerIs("psych.rb")) {
try {
getContext().getFeatureLoader().require("truffle/psych.rb", this);
} catch (IOException e) {
throw new RuntimeException(e);
}

return true;
}

// TODO CS 1-Mar-15 ERB will use strscan if it's there, but strscan is not yet complete, so we need to hide it

if (feature.equals("strscan") && RubyCallStack.getCallerFrame(getContext()).getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith("erb.rb")) {
throw new RaiseException(getContext().getCoreLibrary().loadErrorCannotLoad(feature, this));
}

// TODO CS 19-May-15 securerandom will use openssl if it's there, but we've only shimmed it

if (feature.equals("openssl") && RubyCallStack.getCallerFrame(getContext()).getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith("securerandom.rb")) {
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).getConstants().remove("OpenSSL");
if (feature.equals("strscan") && callerIs("erb.rb")) {
throw new RaiseException(getContext().getCoreLibrary().loadErrorCannotLoad(feature, this));
}

@@ -1564,6 +1535,11 @@ public boolean require(DynamicObject featureString) {
throw new RuntimeException(e);
}
}

private boolean callerIs(String caller) {
return RubyCallStack.getCallerFrame(getContext()).getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith(caller);
}
}

@CoreMethod(names = "require_relative", isModuleFunction = true, required = 1)
Original file line number Diff line number Diff line change
@@ -556,7 +556,7 @@ public DynamicObject autoload(DynamicObject module, String name, DynamicObject f
throw new RaiseException(getContext().getCoreLibrary().argumentError("empty file name", this));
}

if (alreadyLoaded.profile(Layouts.MODULE.getFields(module).getConstants().get(name) != null)) {
if (alreadyLoaded.profile(Layouts.MODULE.getFields(module).getConstant(name) != null)) {
return nil();
}

@@ -834,14 +834,14 @@ public DynamicObject constants(DynamicObject module, boolean inherit) {

final List<DynamicObject> constantsArray = new ArrayList<>();

final Map<String, RubyConstant> constants;
final Iterable<Entry<String, RubyConstant>> constants;
if (inherit) {
constants = ModuleOperations.getAllConstants(module);
} else {
constants = Layouts.MODULE.getFields(module).getConstants();
}

for (Entry<String, RubyConstant> constant : constants.entrySet()) {
for (Entry<String, RubyConstant> constant : constants) {
if (!constant.getValue().isPrivate()) {
constantsArray.add(getSymbol(constant.getKey()));
}
Original file line number Diff line number Diff line change
@@ -77,13 +77,13 @@ protected DynamicObject getLexicalParentModule(VirtualFrame frame) {

@TruffleBoundary
protected RubyConstant lookupForExistingModule(DynamicObject lexicalParent) {
RubyConstant constant = Layouts.MODULE.getFields(lexicalParent).getConstants().get(name);
RubyConstant constant = Layouts.MODULE.getFields(lexicalParent).getConstant(name);

final DynamicObject objectClass = getContext().getCoreLibrary().getObjectClass();

if (constant == null && lexicalParent == objectClass) {
for (DynamicObject included : Layouts.MODULE.getFields(objectClass).prependedAndIncludedModules()) {
constant = Layouts.MODULE.getFields(included).getConstants().get(name);
constant = Layouts.MODULE.getFields(included).getConstant(name);
if (constant != null) {
break;
}
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.layouts.Layouts;
@@ -56,26 +57,28 @@ public static boolean canBindMethodTo(DynamicObject origin, DynamicObject module
}

@TruffleBoundary
public static Map<String, RubyConstant> getAllConstants(DynamicObject module) {
public static Iterable<Entry<String, RubyConstant>> getAllConstants(DynamicObject module) {
CompilerAsserts.neverPartOfCompilation();

assert RubyGuards.isRubyModule(module);

final Map<String, RubyConstant> constants = new HashMap<>();

// Look in the current module
constants.putAll(Layouts.MODULE.getFields(module).getConstants());
for (Map.Entry<String, RubyConstant> constant : Layouts.MODULE.getFields(module).getConstants()) {
constants.put(constant.getKey(), constant.getValue());
}

// Look in ancestors
for (DynamicObject ancestor : Layouts.MODULE.getFields(module).prependedAndIncludedModules()) {
for (Map.Entry<String, RubyConstant> constant : Layouts.MODULE.getFields(ancestor).getConstants().entrySet()) {
for (Map.Entry<String, RubyConstant> constant : Layouts.MODULE.getFields(ancestor).getConstants()) {
if (!constants.containsKey(constant.getKey())) {
constants.put(constant.getKey(), constant.getValue());
}
}
}

return constants;
return constants.entrySet();
}

@TruffleBoundary
@@ -84,14 +87,14 @@ public static RubyConstant lookupConstant(RubyContext context, DynamicObject mod
assert RubyGuards.isRubyModule(module);

// Look in the current module
RubyConstant constant = Layouts.MODULE.getFields(module).getConstants().get(name);
RubyConstant constant = Layouts.MODULE.getFields(module).getConstant(name);
if (constant != null) {
return constant;
}

// Look in ancestors
for (DynamicObject ancestor : Layouts.MODULE.getFields(module).parentAncestors()) {
constant = Layouts.MODULE.getFields(ancestor).getConstants().get(name);
constant = Layouts.MODULE.getFields(ancestor).getConstant(name);
if (constant != null) {
return constant;
}
@@ -106,13 +109,13 @@ private static RubyConstant lookupConstantInObject(RubyContext context, DynamicO
if (!RubyGuards.isRubyClass(module)) {
final DynamicObject objectClass = context.getCoreLibrary().getObjectClass();

RubyConstant constant = Layouts.MODULE.getFields(objectClass).getConstants().get(name);
RubyConstant constant = Layouts.MODULE.getFields(objectClass).getConstant(name);
if (constant != null) {
return constant;
}

for (DynamicObject ancestor : Layouts.MODULE.getFields(objectClass).prependedAndIncludedModules()) {
constant = Layouts.MODULE.getFields(ancestor).getConstants().get(name);
constant = Layouts.MODULE.getFields(ancestor).getConstant(name);
if (constant != null) {
return constant;
}
@@ -141,7 +144,7 @@ public static RubyConstant lookupConstantWithLexicalScope(RubyContext context, L

// Look in lexical scope
while (lexicalScope != context.getRootLexicalScope()) {
constant = Layouts.MODULE.getFields(lexicalScope.getLiveModule()).getConstants().get(name);
constant = Layouts.MODULE.getFields(lexicalScope.getLiveModule()).getConstant(name);
if (constant != null) {
return constant;
}
@@ -195,7 +198,7 @@ public static RubyConstant lookupConstantWithInherit(RubyContext context, Dynami
if (inherit) {
return ModuleOperations.lookupConstantAndObject(context, module, name);
} else {
return Layouts.MODULE.getFields(module).getConstants().get(name);
return Layouts.MODULE.getFields(module).getConstant(name);
}
}

Original file line number Diff line number Diff line change
@@ -578,7 +578,7 @@ public SafepointManager getSafepointManager() {
return safepointManager;
}

public Random getRandom() {
public ThreadLocalRandom getRandom() {
return ThreadLocalRandom.current();
}

Original file line number Diff line number Diff line change
@@ -1470,7 +1470,7 @@ public DynamicObject getNilObject() {
}

public DynamicObject getENV() {
return (DynamicObject) Layouts.MODULE.getFields(objectClass).getConstants().get("ENV").getValue();
return (DynamicObject) Layouts.MODULE.getFields(objectClass).getConstant("ENV").getValue();
}

public ArrayNodes.MinBlock getArrayMinBlock() {
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
import org.jruby.truffle.runtime.object.ObjectIDOperations;

import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

public class ModuleFields implements ModuleChain, ObjectGraphNode {
@@ -286,15 +287,13 @@ public void setAutoloadConstant(RubyContext context, Node currentNode, String na

public void setConstantInternal(RubyContext context, Node currentNode, String name, Object value, boolean autoload) {
checkFrozen(context, currentNode);
// TODO(CS): warn when redefining a constant
// TODO (nirvdrum 18-Feb-15): But don't warn when redefining an autoloaded constant.

RubyConstant previous = constants.get(name);
if (previous == null) {
constants.put(name, new RubyConstant(rubyModuleObject, value, false, autoload));
} else {
// TODO(CS): warn when redefining a constant
// TODO (nirvdrum 18-Feb-15): But don't warn when redefining an autoloaded constant.
constants.put(name, new RubyConstant(rubyModuleObject, value, previous.isPrivate(), autoload));
}
final RubyConstant previous = constants.get(name);
final boolean isPrivate = previous != null && previous.isPrivate();

constants.put(name, new RubyConstant(rubyModuleObject, value, isPrivate, autoload));

newLexicalVersion();
}
@@ -505,8 +504,12 @@ public Assumption getUnmodifiedAssumption() {
return unmodifiedAssumption.getAssumption();
}

public Map<String, RubyConstant> getConstants() {
return constants;
public Iterable<Entry<String, RubyConstant>> getConstants() {
return constants.entrySet();
}

public RubyConstant getConstant(String name) {
return constants.get(name);
}

public Map<String, InternalMethod> getMethods() {