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: c08ca7ae5da7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 477d6a6ed625
Choose a head ref
  • 5 commits
  • 10 files changed
  • 1 contributor

Commits on Feb 14, 2016

  1. Copy the full SHA
    bc0514d View commit details
  2. Copy the full SHA
    ce52aa6 View commit details
  3. [Truffle] Make the MemoryManager part of the NativePlatform, and prov…

    …ide a minimal implementation for Java.
    chrisseaton committed Feb 14, 2016
    Copy the full SHA
    cf1d165 View commit details
  4. Copy the full SHA
    523249c View commit details
  5. Copy the full SHA
    477d6a6 View commit details
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
final int required = method.required();
final int optional = method.optional();
final boolean needsCallerFrame = method.needsCallerFrame();
final boolean alwaysInline = needsCallerFrame && context.getOptions().TRUFFLE_INLINE_NEEDS_CALLER_FRAME;
final boolean alwaysInline = needsCallerFrame && context.getOptions().INLINE_NEEDS_CALLER_FRAME;

final Arity arity = new Arity(required, optional, method.rest());

Original file line number Diff line number Diff line change
@@ -509,7 +509,7 @@ public int accept(DynamicObject io) {
final int newFd;

try {
newFd = nativeSockets().accept(fd, getMemoryManager().newPointer(address), addressLength);
newFd = nativeSockets().accept(fd, memoryManager().newPointer(address), addressLength);
} finally {
UnsafeHolder.U.freeMemory(address);
}
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ public DynamicObject malloc(DynamicObject pointerClass, int size) {
@SuppressWarnings("restriction")
@Specialization
public DynamicObject malloc(DynamicObject pointerClass, long size) {
return allocateObjectNode.allocate(pointerClass, getMemoryManager().newPointer(UnsafeHolder.U.allocateMemory(size)));
return allocateObjectNode.allocate(pointerClass, memoryManager().newPointer(UnsafeHolder.U.allocateMemory(size)));
}

}
@@ -108,7 +108,7 @@ public long setAddress(DynamicObject pointer, int address) {

@Specialization
public long setAddress(DynamicObject pointer, long address) {
Layouts.POINTER.setPointer(pointer, getMemoryManager().newPointer(address));
Layouts.POINTER.setPointer(pointer, memoryManager().newPointer(address));
return address;
}

@@ -131,7 +131,7 @@ public DynamicObject add(DynamicObject a, int b) {

@Specialization
public DynamicObject add(DynamicObject a, long b) {
return allocateObjectNode.allocate(Layouts.BASIC_OBJECT.getLogicalClass(a), getMemoryManager().newPointer(Layouts.POINTER.getPointer(a).address() + b));
return allocateObjectNode.allocate(Layouts.BASIC_OBJECT.getLogicalClass(a), memoryManager().newPointer(Layouts.POINTER.getPointer(a).address() + b));
}

}
80 changes: 41 additions & 39 deletions truffle/src/main/java/org/jruby/truffle/language/Options.java
Original file line number Diff line number Diff line change
@@ -9,70 +9,72 @@
*/
package org.jruby.truffle.language;

import static org.jruby.util.cli.Options.*;

public class Options {

// Features

public final boolean COVERAGE = org.jruby.util.cli.Options.TRUFFLE_COVERAGE.load();
public final boolean COVERAGE_GLOBAL = org.jruby.util.cli.Options.TRUFFLE_COVERAGE_GLOBAL.load();
public final boolean COVERAGE = TRUFFLE_COVERAGE.load();
public final boolean COVERAGE_GLOBAL = TRUFFLE_COVERAGE_GLOBAL.load();

// Resources

public final String CORE_LOAD_PATH = org.jruby.util.cli.Options.TRUFFLE_CORE_LOAD_PATH.load();
public final boolean PLATFORM_USE_JAVA = org.jruby.util.cli.Options.TRUFFLE_PLATFORM_USE_JAVA.load();
public final String CORE_LOAD_PATH = TRUFFLE_CORE_LOAD_PATH.load();
public final boolean PLATFORM_USE_JAVA = TRUFFLE_PLATFORM_USE_JAVA.load();

// Data structures

public final int ARRAY_UNINITIALIZED_SIZE = org.jruby.util.cli.Options.TRUFFLE_ARRAY_UNINITIALIZED_SIZE.load();
public final int ARRAY_SMALL = org.jruby.util.cli.Options.TRUFFLE_ARRAY_SMALL.load();
public final int ARRAY_UNINITIALIZED_SIZE = TRUFFLE_ARRAY_UNINITIALIZED_SIZE.load();
public final int ARRAY_SMALL = TRUFFLE_ARRAY_SMALL.load();

public final int HASH_PACKED_ARRAY_MAX = org.jruby.util.cli.Options.TRUFFLE_HASH_PACKED_ARRAY_MAX.load();
public final int HASH_PACKED_ARRAY_MAX = TRUFFLE_HASH_PACKED_ARRAY_MAX.load();

// Caches

public final int METHOD_LOOKUP_CACHE = org.jruby.util.cli.Options.TRUFFLE_METHOD_LOOKUP_CACHE.load();
public final int DISPATCH_CACHE = org.jruby.util.cli.Options.TRUFFLE_DISPATCH_CACHE.load();
public final int YIELD_CACHE = org.jruby.util.cli.Options.TRUFFLE_YIELD_CACHE.load();
public final int METHOD_TO_PROC_CACHE = org.jruby.util.cli.Options.TRUFFLE_METHOD_TO_PROC_CACHE.load();
public final int IS_A_CACHE = org.jruby.util.cli.Options.TRUFFLE_IS_A_CACHE.load();
public final int BIND_CACHE = org.jruby.util.cli.Options.TRUFFLE_BIND_CACHE.load();
public final int CONSTANT_CACHE = org.jruby.util.cli.Options.TRUFFLE_CONSTANT_CACHE.load();
public final int INSTANCE_VARIABLE_CACHE = org.jruby.util.cli.Options.TRUFFLE_INSTANCE_VARIABLE_CACHE.load();
public final int BINDING_LOCAL_VARIABLE_CACHE = org.jruby.util.cli.Options.TRUFFLE_BINDING_LOCAL_VARIABLE_CACHE.load();
public final int SYMBOL_TO_PROC_CACHE = org.jruby.util.cli.Options.TRUFFLE_SYMBOL_TO_PROC_CACHE.load();
public final int ALLOCATE_CLASS_CACHE = org.jruby.util.cli.Options.TRUFFLE_ALLOCATE_CLASS_CACHE.load();
public final int PACK_CACHE = org.jruby.util.cli.Options.TRUFFLE_PACK_CACHE.load();
public final int UNPACK_CACHE = org.jruby.util.cli.Options.TRUFFLE_UNPACK_CACHE.load();
public final int EVAL_CACHE = org.jruby.util.cli.Options.TRUFFLE_EVAL_CACHE.load();
public final int ENCODING_COMPATIBILE_QUERY_CACHE = org.jruby.util.cli.Options.TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE.load();
public final int METHOD_LOOKUP_CACHE = TRUFFLE_METHOD_LOOKUP_CACHE.load();
public final int DISPATCH_CACHE = TRUFFLE_DISPATCH_CACHE.load();
public final int YIELD_CACHE = TRUFFLE_YIELD_CACHE.load();
public final int METHOD_TO_PROC_CACHE = TRUFFLE_METHOD_TO_PROC_CACHE.load();
public final int IS_A_CACHE = TRUFFLE_IS_A_CACHE.load();
public final int BIND_CACHE = TRUFFLE_BIND_CACHE.load();
public final int CONSTANT_CACHE = TRUFFLE_CONSTANT_CACHE.load();
public final int INSTANCE_VARIABLE_CACHE = TRUFFLE_INSTANCE_VARIABLE_CACHE.load();
public final int BINDING_LOCAL_VARIABLE_CACHE = TRUFFLE_BINDING_LOCAL_VARIABLE_CACHE.load();
public final int SYMBOL_TO_PROC_CACHE = TRUFFLE_SYMBOL_TO_PROC_CACHE.load();
public final int ALLOCATE_CLASS_CACHE = TRUFFLE_ALLOCATE_CLASS_CACHE.load();
public final int PACK_CACHE = TRUFFLE_PACK_CACHE.load();
public final int UNPACK_CACHE = TRUFFLE_UNPACK_CACHE.load();
public final int EVAL_CACHE = TRUFFLE_EVAL_CACHE.load();
public final int ENCODING_COMPATIBILE_QUERY_CACHE = TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE.load();

// Cloning and inlining

public final boolean CORE_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_CORE_ALWAYS_CLONE.load();
public final boolean TRUFFLE_INLINE_NEEDS_CALLER_FRAME = org.jruby.util.cli.Options.TRUFFLE_INLINE_NEEDS_CALLER_FRAME.load();
public final boolean YIELD_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_YIELD_ALWAYS_CLONE.load();
public final boolean YIELD_ALWAYS_INLINE = org.jruby.util.cli.Options.TRUFFLE_YIELD_ALWAYS_INLINE.load();
public final boolean METHODMISSING_ALWAYS_CLONE = org.jruby.util.cli.Options.TRUFFLE_METHODMISSING_ALWAYS_CLONE.load();
public final boolean METHODMISSING_ALWAYS_INLINE = org.jruby.util.cli.Options.TRUFFLE_METHODMISSING_ALWAYS_INLINE.load();
public final boolean CORE_ALWAYS_CLONE = TRUFFLE_CORE_ALWAYS_CLONE.load();
public final boolean INLINE_NEEDS_CALLER_FRAME = TRUFFLE_INLINE_NEEDS_CALLER_FRAME.load();
public final boolean YIELD_ALWAYS_CLONE = TRUFFLE_YIELD_ALWAYS_CLONE.load();
public final boolean YIELD_ALWAYS_INLINE = TRUFFLE_YIELD_ALWAYS_INLINE.load();
public final boolean METHODMISSING_ALWAYS_CLONE = TRUFFLE_METHODMISSING_ALWAYS_CLONE.load();
public final boolean METHODMISSING_ALWAYS_INLINE = TRUFFLE_METHODMISSING_ALWAYS_INLINE.load();

// Other tuning parameteres

public final int PACK_UNROLL_LIMIT = org.jruby.util.cli.Options.TRUFFLE_PACK_UNROLL_LIMIT.load();
public final int PACK_RECOVER_LOOP_MIN = org.jruby.util.cli.Options.TRUFFLE_PACK_RECOVER_LOOP_MIN.load();
public final int PACK_UNROLL_LIMIT = TRUFFLE_PACK_UNROLL_LIMIT.load();
public final int PACK_RECOVER_LOOP_MIN = TRUFFLE_PACK_RECOVER_LOOP_MIN.load();

// Debugging

public final int INSTRUMENTATION_SERVER_PORT = org.jruby.util.cli.Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load();
public final boolean EXCEPTIONS_PRINT_JAVA = org.jruby.util.cli.Options.TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public final boolean EXCEPTIONS_PRINT_UNCAUGHT_JAVA = org.jruby.util.cli.Options.TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA.load();
public final boolean BACKTRACES_HIDE_CORE_FILES = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_HIDE_CORE_FILES.load();
public final int BACKTRACES_LIMIT = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_LIMIT.load();
public final boolean BACKTRACES_OMIT_UNUSED = org.jruby.util.cli.Options.TRUFFLE_BACKTRACES_OMIT_UNUSED.load();
public final boolean INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = org.jruby.util.cli.Options.TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC.load();
public final int INSTRUMENTATION_SERVER_PORT = TRUFFLE_INSTRUMENTATION_SERVER_PORT.load();
public final boolean EXCEPTIONS_PRINT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public final boolean EXCEPTIONS_PRINT_UNCAUGHT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA.load();
public final boolean BACKTRACES_HIDE_CORE_FILES = TRUFFLE_BACKTRACES_HIDE_CORE_FILES.load();
public final int BACKTRACES_LIMIT = TRUFFLE_BACKTRACES_LIMIT.load();
public final boolean BACKTRACES_OMIT_UNUSED = TRUFFLE_BACKTRACES_OMIT_UNUSED.load();
public final boolean INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC.load();

// Call graph

public final boolean CALL_GRAPH = org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH.load();
public final String CALL_GRAPH_WRITE = org.jruby.util.cli.Options.TRUFFLE_CALL_GRAPH_WRITE.load();
public final boolean CALL_GRAPH = TRUFFLE_CALL_GRAPH.load();
public final String CALL_GRAPH_WRITE = TRUFFLE_CALL_GRAPH_WRITE.load();

}
59 changes: 21 additions & 38 deletions truffle/src/main/java/org/jruby/truffle/language/RubyNode.java
Original file line number Diff line number Diff line change
@@ -34,12 +34,6 @@
public abstract class RubyNode extends Node {

private final RubyContext context;

// This field is a hack, used to transmit the information
// supplied by the JRuby parser in the form of a special
// node in the parse tree. The right thing to do is to
// add a special information node when the AST is constructed,
// which can then be removed.
private boolean atNewline = false;

public RubyNode(RubyContext context, SourceSection sourceSection) {
@@ -52,16 +46,14 @@ public RubyNode(RubyContext context, SourceSection sourceSection) {

public abstract Object execute(VirtualFrame frame);

public Object isDefined(VirtualFrame frame) {
return create7BitString("expression", UTF8Encoding.INSTANCE);
}

// Execute without returning the result

public void executeVoid(VirtualFrame frame) {
execute(frame);
}

public Object isDefined(VirtualFrame frame) {
return create7BitString("expression", UTF8Encoding.INSTANCE);
}

// Utility methods to execute and expect a particular type

public NotProvided executeNotProvided(VirtualFrame frame) throws UnexpectedResultException {
@@ -144,25 +136,28 @@ protected boolean isRubiniusUndefined(Object value) {
return value == getContext().getCoreLibrary().getRubiniusUndefined();
}

protected DynamicObjectFactory getInstanceFactory(DynamicObject rubyClass) {
return Layouts.CLASS.getInstanceFactory(rubyClass);
}

// Helpers methods for terseness

protected DynamicObject nil() {
return getContext().getCoreLibrary().getNilObject();
}

public DynamicObject getSymbol(String name) {
protected DynamicObject getSymbol(String name) {
return getContext().getSymbolTable().getSymbol(name);
}

public DynamicObject getSymbol(ByteList name) {
protected DynamicObject getSymbol(ByteList name) {
return getContext().getSymbolTable().getSymbol(name);
}

public DynamicObject getSymbol(Rope name) {
protected DynamicObject getSymbol(Rope name) {
return getContext().getSymbolTable().getSymbol(name);
}

/** Creates a String from the ByteList, with unknown CR */
protected DynamicObject createString(ByteList bytes) {
return StringOperations.createString(getContext(), bytes);
}
@@ -183,22 +178,16 @@ protected Sockets nativeSockets() {
return getContext().getNativePlatform().getSockets();
}

// Helper methods for caching

protected DynamicObjectFactory getInstanceFactory(DynamicObject rubyClass) {
return Layouts.CLASS.getInstanceFactory(rubyClass);
}

public void setAtNewline() {
atNewline = true;
protected MemoryManager memoryManager() {
return getContext().getNativePlatform().getMemoryManager();
}

public boolean isAtNewline() {
return atNewline;
protected Object ruby(String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, expression, arguments);
}

public RubyNode getNonProxyNode() {
return this;
protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, frame, expression, arguments);
}

// Accessors
@@ -207,18 +196,12 @@ public RubyContext getContext() {
return context;
}

public MemoryManager getMemoryManager() {
return jnr.ffi.Runtime.getSystemRuntime().getMemoryManager();
}

// ruby() helper

protected Object ruby(String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, expression, arguments);
public void setAtNewline() {
atNewline = true;
}

protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
return getContext().getCodeLoader().inlineRubyHelper(this, frame, expression, arguments);
public boolean isAtNewline() {
return atNewline;
}

}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.platform;

import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import org.jruby.truffle.core.queue.ArrayBlockingQueueLocksConditions;
import org.jruby.truffle.core.queue.LinkedBlockingQueueLocksConditions;
@@ -18,6 +19,8 @@ public interface NativePlatform {

POSIX getPosix();

MemoryManager getMemoryManager();

SignalManager getSignalManager();

ProcessName getProcessName();
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
package org.jruby.truffle.platform.darwin;

import jnr.ffi.LibraryLoader;
import jnr.ffi.Runtime;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;
import jnr.posix.POSIXFactory;
import org.jruby.truffle.RubyContext;
@@ -31,6 +33,7 @@
public class DarwinPlatform implements NativePlatform {

private final POSIX posix;
private final MemoryManager memoryManager;
private final SignalManager signalManager;
private final ProcessName processName;
private final Sockets sockets;
@@ -39,6 +42,7 @@ public class DarwinPlatform implements NativePlatform {

public DarwinPlatform(RubyContext context) {
posix = POSIXFactory.getNativePOSIX(new TrufflePOSIXHandler(context));
memoryManager = Runtime.getSystemRuntime().getMemoryManager();
signalManager = new SunMiscSignalManager();
processName = new DarwinProcessName();
sockets = LibraryLoader.create(Sockets.class).library("c").load();
@@ -53,6 +57,11 @@ public POSIX getPosix() {
return posix;
}

@Override
public MemoryManager getMemoryManager() {
return memoryManager;
}

@Override
public SignalManager getSignalManager() {
return signalManager;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 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.platform.java;

import jnr.ffi.Pointer;
import jnr.ffi.provider.InAccessibleMemoryIO;
import jnr.ffi.provider.MemoryManager;
import jnr.ffi.provider.NullMemoryIO;

import java.nio.ByteBuffer;

public class JavaMemoryManager implements MemoryManager {

@Override
public Pointer allocate(int size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateDirect(int size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateDirect(int size, boolean clear) {
throw new UnsupportedOperationException();
}

@Override
public Pointer allocateTemporary(int size, boolean clear) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newPointer(ByteBuffer buffer) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newPointer(long address) {
if (address == 0) {
return new NullMemoryIO(null);
} else {
throw new UnsupportedOperationException();
}
}

@Override
public Pointer newPointer(long address, long size) {
throw new UnsupportedOperationException();
}

@Override
public Pointer newOpaquePointer(long address) {
throw new UnsupportedOperationException();
}

}
Loading