Skip to content

Commit

Permalink
[Truffle] More privatisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 4, 2016
1 parent c15bf67 commit 55e5574
Show file tree
Hide file tree
Showing 48 changed files with 2,767 additions and 81 deletions.
2 changes: 0 additions & 2 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -46,7 +46,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
import org.jruby.util.cli.OutputStrings;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;
Expand All @@ -60,7 +59,6 @@
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand Down
2 changes: 1 addition & 1 deletion truffle/src/main/java/org/jruby/truffle/Main.java
Expand Up @@ -48,7 +48,7 @@
import org.jruby.truffle.options.OptionsBuilder;
import org.jruby.truffle.options.OptionsCatalog;
import org.jruby.truffle.options.RubyInstanceConfig;
import org.jruby.util.cli.OutputStrings;
import org.jruby.truffle.options.OutputStrings;

import java.io.InputStream;
import java.lang.management.ManagementFactory;
Expand Down
Expand Up @@ -44,7 +44,7 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.util.unsafe.UnsafeHolder;
import org.jruby.truffle.util.UnsafeHolder;

import java.util.HashMap;
import java.util.Map;
Expand Down
6 changes: 2 additions & 4 deletions truffle/src/main/java/org/jruby/truffle/core/Hashing.java
Expand Up @@ -9,14 +9,12 @@
*/
package org.jruby.truffle.core;

import org.jruby.util.cli.Options;

import java.util.Random;

public class Hashing {

private static final boolean SIPHASH_ENABLED = Options.SIPHASH_ENABLED.load();
private static final boolean CONSISTENT_HASHING_ENABLED = Options.CONSISTENT_HASHING.load();
private static final boolean SIPHASH_ENABLED = false;
private static final boolean CONSISTENT_HASHING_ENABLED = false;

private static final int MURMUR2_MAGIC = 0x5bd1e995;

Expand Down
Expand Up @@ -49,10 +49,8 @@
import org.jruby.truffle.builtins.CoreMethodNode;
import org.jruby.truffle.builtins.YieldingCoreMethodNode;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.util.unsafe.UnsafeHolder;
import org.jruby.truffle.util.UnsafeHolder;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@CoreClass("Truffle::System")
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.util.Memo;
import org.jruby.truffle.util.Memo;

@CoreClass("Truffle::Binding")
public abstract class TruffleBindingNodes {
Expand Down
Expand Up @@ -17,17 +17,18 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;
import org.jruby.util.func.Function0;

import java.util.function.Supplier;

@NodeChild(value = "value", type = RubyNode.class)
public abstract class LazyDefaultValueNode extends RubyNode {

private final Function0<Object> defaultValueProducer;
private final Supplier<Object> defaultValueProducer;

@CompilationFinal private boolean hasDefault;
@CompilationFinal private Object defaultValue;

public LazyDefaultValueNode(RubyContext context, SourceSection sourceSection, Function0<Object> defaultValueProducer) {
public LazyDefaultValueNode(RubyContext context, SourceSection sourceSection, Supplier<Object> defaultValueProducer) {
super(context, sourceSection);
this.defaultValueProducer = defaultValueProducer;
}
Expand All @@ -36,7 +37,7 @@ public LazyDefaultValueNode(RubyContext context, SourceSection sourceSection, Fu
public Object doDefault(NotProvided value) {
if (!hasDefault) {
CompilerDirectives.transferToInterpreterAndInvalidate();
defaultValue = defaultValueProducer.apply();
defaultValue = defaultValueProducer.get();
hasDefault = true;
}

Expand Down
Expand Up @@ -26,7 +26,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.printf.PrintfSimpleTreeBuilder;
import org.jruby.util.ByteList;
import org.jruby.util.ConvertBytes;
import org.jruby.truffle.util.ConvertBytes;

import java.math.BigInteger;

Expand Down
Expand Up @@ -57,7 +57,7 @@
import org.jruby.truffle.core.format.exceptions.InvalidFormatException;
import org.jruby.truffle.core.format.read.SourceNode;
import org.jruby.truffle.core.rope.AsciiOnlyLeafRope;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.read.SourceNode;
import org.jruby.truffle.core.rope.AsciiOnlyLeafRope;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.read.SourceNode;
import org.jruby.truffle.core.rope.AsciiOnlyLeafRope;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.read.SourceNode;
import org.jruby.truffle.core.rope.AsciiOnlyLeafRope;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

import java.nio.ByteBuffer;
import java.util.Arrays;
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.exceptions.NoImplicitConversionException;
import org.jruby.util.ByteList;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
Expand Down
Expand Up @@ -17,7 +17,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.util.ByteList;
import org.jruby.util.PackUtils;
import org.jruby.truffle.util.PackUtils;

@NodeChildren({
@NodeChild(value = "value", type = FormatNode.class),
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.exceptions.NoImplicitConversionException;
import org.jruby.util.ByteList;
import org.jruby.util.Pack;
import org.jruby.truffle.util.Pack;

/**
* Read a string that contains UU-encoded data and write as actual binary
Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.methods.UnsupportedOperationBehavior;
import org.jruby.util.SipHashInline;
import org.jruby.truffle.util.SipHashInline;

import java.math.BigInteger;
import java.nio.ByteBuffer;
Expand Down
Expand Up @@ -50,8 +50,8 @@
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.parser.ReOptions;
import org.jruby.util.ByteList;
import org.jruby.util.collections.WeakValuedMap;
import org.jruby.util.io.EncodingUtils;
import org.jruby.truffle.util.WeakValuedMap;
import org.jruby.truffle.util.EncodingUtils;

import java.nio.charset.StandardCharsets;
import java.util.Iterator;
Expand Down
Expand Up @@ -33,10 +33,10 @@
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.util.EncodingUtils;
import org.jruby.truffle.util.Memo;
import org.jruby.truffle.util.StringUtils;
import org.jruby.util.ByteList;
import org.jruby.util.Memo;
import org.jruby.util.io.EncodingUtils;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
Expand Down
Expand Up @@ -75,7 +75,7 @@
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.ByteList;
import org.jruby.util.Dir;
import org.jruby.util.unsafe.UnsafeHolder;
import org.jruby.truffle.util.UnsafeHolder;

import java.nio.ByteBuffer;

Expand Down
Expand Up @@ -15,9 +15,9 @@
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.util.CodeRangeable;
import org.jruby.truffle.util.StringUtils;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;

public class StringCodeRangeableWrapper implements CodeRangeable {

Expand Down
Expand Up @@ -145,10 +145,10 @@
import org.jruby.truffle.language.objects.TaintNode;
import org.jruby.truffle.language.objects.TaintNodeGen;
import org.jruby.truffle.platform.posix.TrufflePosix;
import org.jruby.truffle.util.CodeRangeable;
import org.jruby.truffle.util.StringUtils;
import org.jruby.util.ByteList;
import org.jruby.util.CodeRangeable;
import org.jruby.util.ConvertDouble;
import org.jruby.truffle.util.ConvertDouble;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
Expand Down
Expand Up @@ -32,22 +32,20 @@
import org.jcodings.specific.UTF8Encoding;
import org.jcodings.util.IntHash;
import org.joni.Matcher;
import org.jruby.truffle.util.ByteListHolder;
import org.jruby.truffle.util.CodeRangeSupport;
import org.jruby.truffle.util.CodeRangeable;
import org.jruby.util.ByteList;
import org.jruby.util.ByteListHolder;
import org.jruby.util.CodeRangeSupport;
import org.jruby.util.CodeRangeable;
import org.jruby.util.Sprintf;
import org.jruby.util.collections.IntHashMap;
import org.jruby.util.io.EncodingUtils;
import org.jruby.truffle.util.IntHashMap;
import sun.misc.Unsafe;
import org.jruby.truffle.util.EncodingUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.jcodings.Encoding.CHAR_INVALID;
import static org.jruby.RubyEnumerator.enumeratorize;

public final class StringSupport {
public static final int CR_7BIT_F = 16;
Expand Down
Expand Up @@ -72,7 +72,7 @@
import org.jruby.truffle.language.objects.ReadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadObjectFieldNodeGen;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.Memo;
import org.jruby.truffle.util.Memo;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.jruby.truffle.platform.RubiniusTypes;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.util.ByteList;
import org.jruby.util.unsafe.UnsafeHolder;
import org.jruby.truffle.util.UnsafeHolder;

public abstract class PointerPrimitiveNodes {
public static final Pointer NULL_POINTER = jnr.ffi.Runtime.getSystemRuntime().getMemoryManager().newOpaquePointer(0);
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.parser.ParserContext;
import org.jruby.truffle.parser.TranslatorDriver;
import org.jruby.util.Memo;
import org.jruby.truffle.util.Memo;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Expand Up @@ -29,10 +29,9 @@
package org.jruby.truffle.options;

import org.jruby.truffle.core.string.StringSupport;
import org.jruby.truffle.util.SafePropertyAccessor;
import org.jruby.util.FileResource;
import org.jruby.util.JRubyFile;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.func.Function2;

import java.io.File;
import java.io.IOException;
Expand All @@ -43,6 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -543,7 +543,7 @@ private void processArgument() {
}

private void enableDisableFeature(String name, boolean enable) {
Function2<Boolean, ArgumentProcessor, Boolean> feature = FEATURES.get(name);
BiFunction<ArgumentProcessor, Boolean, Boolean> feature = FEATURES.get(name);

if (feature == null) {
config.getError().println("warning: unknown argument for --" + (enable ? "enable" : "disable") + ": `" + name + "'");
Expand Down Expand Up @@ -740,35 +740,35 @@ private static boolean isPropertySupported(String propertyName) {
return false;
}

private static final Map<String, Function2<Boolean, ArgumentProcessor, Boolean>> FEATURES;
private static final Map<String, BiFunction<ArgumentProcessor, Boolean, Boolean>> FEATURES;

static {
Map<String, Function2<Boolean, ArgumentProcessor, Boolean>> features = new HashMap<>(12, 1);
Function2<Boolean, ArgumentProcessor, Boolean> function2;
Map<String, BiFunction<ArgumentProcessor, Boolean, Boolean>> features = new HashMap<>(12, 1);
BiFunction<ArgumentProcessor, Boolean, Boolean> function2;

features.put("all", new Function2<Boolean, ArgumentProcessor, Boolean>() {
features.put("all", new BiFunction<ArgumentProcessor, Boolean, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
// disable all features
for (Map.Entry<String, Function2<Boolean, ArgumentProcessor, Boolean>> entry : FEATURES.entrySet()) {
for (Map.Entry<String, BiFunction<ArgumentProcessor, Boolean, Boolean>> entry : FEATURES.entrySet()) {
if (entry.getKey().equals("all")) continue; // skip self
entry.getValue().apply(processor, enable);
}
return true;
}
});
features.put("gem", new Function2<Boolean, ArgumentProcessor, Boolean>() {
features.put("gem", new BiFunction<ArgumentProcessor, Boolean, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setDisableGems(!enable);
return true;
}
});
features.put("gems", new Function2<Boolean, ArgumentProcessor, Boolean>() {
features.put("gems", new BiFunction<ArgumentProcessor, Boolean, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setDisableGems(!enable);
return true;
}
});
features.put("frozen-string-literal", function2 = new Function2<Boolean, ArgumentProcessor, Boolean>() {
features.put("frozen-string-literal", function2 = new BiFunction<ArgumentProcessor, Boolean, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setFrozenStringLiteral(enable);
return true;
Expand Down
Expand Up @@ -28,8 +28,7 @@
import com.headius.options.Option;
import org.jruby.truffle.util.Constants;
import org.jruby.truffle.util.Platform;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
import org.jruby.truffle.util.SafePropertyAccessor;

/**
* Utility methods to generate the command-line output strings for help,
Expand Down Expand Up @@ -153,7 +152,7 @@ public static String getVersionString() {
SafePropertyAccessor.getProperty("java.vm.version", "Unknown JVM version"),
SafePropertyAccessor.getProperty("java.runtime.version", SafePropertyAccessor.getProperty("java.version", "Unknown version")),
org.jruby.util.cli.Options.COMPILE_INVOKEDYNAMIC.load() ? " +indy" : "",
Options.COMPILE_MODE.load().shouldJIT() ? " +jit" : "",
"truffle",
Platform.getOSName(),
Platform.getArchitecture()
);
Expand Down

0 comments on commit 55e5574

Please sign in to comment.