Skip to content

Commit

Permalink
Cleanup and centralize all property-based configuration settings.
Browse files Browse the repository at this point in the history
Properties for JRuby are now all in one location, combined with information
on valid options, defaults, and description. All properties going forward
should follow the same format, to ensure they're documented in the jruby
--properties output.

I have added to this new form all properties I thought were interesting to
expose. There are a few still hidden that may be deleted soon.

I also removed some long-defunct properties and removed unused code that related
to them.
  • Loading branch information
headius committed Oct 27, 2011
1 parent 95fec3d commit 4a83308
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 365 deletions.
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
<include name="org/jruby/util/CodegenUtils.java"/>
<include name="org/jruby/util/log/*.java"/>
<include name="org/jruby/util/SafePropertyAccessor.java"/>
<include name="org/jruby/util/cli/Properties.java"/>
</javac>
</target>

Expand Down
4 changes: 4 additions & 0 deletions src/org/jruby/CompatVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ public enum CompatVersion {
public static CompatVersion getVersionFromString(String compatString) {
if (compatString.equalsIgnoreCase("RUBY1_8")) {
return CompatVersion.RUBY1_8;
} else if (compatString.equalsIgnoreCase("1.8")) {
return CompatVersion.RUBY1_8;
} else if (compatString.equalsIgnoreCase("RUBY1_9")) {
return CompatVersion.RUBY1_9;
} else if (compatString.equalsIgnoreCase("1.9")) {
return CompatVersion.RUBY1_9;
} else {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -4119,7 +4119,7 @@ public StaticScopeFactory getStaticScopeFactory() {
// must be located be in this order!
private volatile static boolean securityRestricted = false;
static {
if (SafePropertyAccessor.isSecurityProtected("jruby.reflection")) {
if (SafePropertyAccessor.isSecurityProtected("jruby.reflected.handles")) {
// can't read non-standard properties
securityRestricted = true;
} else {
Expand Down
253 changes: 100 additions & 153 deletions src/org/jruby/RubyInstanceConfig.java

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/org/jruby/compiler/ASTInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ public CallConfiguration getCallConfig() {
}
}

public static final boolean ENABLED = SafePropertyAccessor.getProperty("jruby.astInspector.enabled", "true").equals("true");

/**
* Perform an inspection of a subtree or set of subtrees separate from the
* parent inspection, to make independent decisions based on that subtree(s).
Expand Down Expand Up @@ -274,7 +272,7 @@ public void integrate(ASTInspector other) {
}

public void inspect(Node node) {
if (!ENABLED || RubyInstanceConfig.FULL_TRACE_ENABLED) {
if (RubyInstanceConfig.FULL_TRACE_ENABLED) {
disable();
return;
}
Expand Down
10 changes: 2 additions & 8 deletions src/org/jruby/compiler/impl/BaseBodyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2596,14 +2596,8 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
CompilerCallback body, CompilerCallback args,
CompilerCallback receiver, ASTInspector inspector, boolean root,
String filename, int line, String parameterDesc) {
// TODO: build arg list based on number of args, optionals, etc
String newMethodName;
if (root && SafePropertyAccessor.getBoolean("jruby.compile.toplevel", false)) {
newMethodName = name;
} else {
String mangledName = JavaNameMangler.mangleMethodName(name);
newMethodName = "method__" + script.getAndIncrementMethodIndex() + "$RUBY$" + mangledName;
}
String mangledName = JavaNameMangler.mangleMethodName(name);
String newMethodName = "method__" + script.getAndIncrementMethodIndex() + "$RUBY$" + mangledName;

BodyCompiler methodCompiler = script.startMethod(name, newMethodName, args, scope, inspector);

Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/compiler/impl/SkinnyMethodAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.PrintWriter;
import java.util.Map;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Properties;
import static org.jruby.util.CodegenUtils.*;

import org.objectweb.asm.AnnotationVisitor;
Expand All @@ -33,7 +34,7 @@
* @author headius
*/
public class SkinnyMethodAdapter extends MethodVisitor implements Opcodes {
private final static boolean DEBUG = SafePropertyAccessor.getBoolean("jruby.compile.dump");
private final static boolean DEBUG = Properties.COMPILE_DUMP.load();
private MethodVisitor method;
private Printer printer;
private String name;
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/ext/JRubyPOSIXHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jnr.posix.POSIXHandler;

import jnr.constants.platform.Errno;
import org.jruby.util.cli.Properties;

public class JRubyPOSIXHandler implements POSIXHandler {
private final Ruby runtime;
Expand All @@ -23,7 +24,7 @@ public JRubyPOSIXHandler(Ruby runtime) {

boolean verbose = false;
try {
verbose = Boolean.getBoolean("jruby.native.verbose");
verbose = Properties.NATIVE_VERBOSE.load();
} catch (SecurityException e) {
}
this.isVerbose = verbose;
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/ext/ffi/jffi/AsmClassBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jruby.compiler.impl.SkinnyMethodAdapter;
import java.lang.reflect.Constructor;
import java.util.concurrent.atomic.AtomicLong;
import org.jruby.util.cli.Properties;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

Expand All @@ -15,7 +16,7 @@
*
*/
final class AsmClassBuilder {
public static final boolean DEBUG = false || Boolean.getBoolean("jruby.ffi.compile.dump");
public static final boolean DEBUG = false || Properties.FFI_COMPILE_DUMP.load();
private static final AtomicLong nextClassID = new AtomicLong(0);
private final JITSignature signature;
private final ClassWriter classWriter;
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/ext/ffi/jffi/DefaultMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.cli.Properties;

class DefaultMethod extends JFFIDynamicMethod {
private final ParameterMarshaller[] marshallers;
Expand Down Expand Up @@ -127,7 +128,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self,

@Override
public synchronized NativeCall getNativeCall() {
if (!Boolean.getBoolean("jruby.ffi.compile.invokedynamic")) {
if (!Properties.FFI_COMPILE_INVOKEDYNAMIC.load()) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/ext/ffi/jffi/IndyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.jruby.util.cli.Properties;

import static org.jruby.util.CodegenUtils.*;
import static org.objectweb.asm.Opcodes.*;
Expand All @@ -23,7 +24,7 @@
*
*/
public final class IndyCompiler {
public static final boolean DEBUG = Boolean.getBoolean("jruby.ffi.compile.dump");
public static final boolean DEBUG = Properties.FFI_COMPILE_DUMP.load();
private static final Map<Class, NativeInvoker> invokers
= Collections.synchronizedMap(new WeakHashMap<Class, NativeInvoker>());
private static final AtomicLong nextClassId = new AtomicLong();
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/ext/ffi/jffi/JITHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import java.lang.reflect.Constructor;
import java.util.concurrent.atomic.AtomicInteger;
import org.jruby.ext.ffi.Type;
import org.jruby.util.cli.Properties;

/**
*
*/
final class JITHandle {

private static final int THRESHOLD = Integer.getInteger("jruby.ffi.compile.threshold", 100);
private static final int THRESHOLD = Properties.FFI_COMPILE_THRESHOLD.load();
private final JITSignature jitSignature;
private volatile boolean compilationFailed = false;
private final AtomicInteger counter = new AtomicInteger(0);
Expand Down
5 changes: 3 additions & 2 deletions src/org/jruby/javasupport/Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@
import org.jruby.java.proxies.JavaProxy;
import org.jruby.java.proxies.RubyObjectHolderProxy;
import org.jruby.util.ClassCache.OneShotClassLoader;
import org.jruby.util.cli.Properties;

@JRubyModule(name = "Java")
public class Java implements Library {
public static final boolean NEW_STYLE_EXTENSION = SafePropertyAccessor.getBoolean("jruby.ji.newStyleExtension", false);
public static final boolean OBJECT_PROXY_CACHE = SafePropertyAccessor.getBoolean("jruby.ji.objectProxyCache", true);
public static final boolean NEW_STYLE_EXTENSION = Properties.JI_NEWSTYLEEXTENSION.load();
public static final boolean OBJECT_PROXY_CACHE = Properties.JI_OBJECTPROXYCACHE.load();

public void load(Ruby runtime, boolean wrap) throws IOException {
createJavaModule(runtime);
Expand Down
3 changes: 2 additions & 1 deletion src/org/jruby/javasupport/JavaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.jruby.util.ByteList;
import org.jruby.util.IdUtil;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Properties;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

Expand All @@ -116,7 +117,7 @@ public class JavaClass extends JavaObject {
} catch (Throwable t) {
// added this so if things are weird in the future we can debug without
// spinning a new binary
if (SafePropertyAccessor.getBoolean("jruby.ji.logCanSetAccessible")) {
if (Properties.JI_LOGCANSETACCESSIBLE.load()) {
t.printStackTrace();
}

Expand Down
6 changes: 0 additions & 6 deletions src/org/jruby/parser/ParserConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class ParserConfiguration {
private boolean isEvalParse = true;
// Should positions added extra IDE-friendly information and leave in all newline nodes
private boolean extraPositionInformation = false;
// Will parser parse Duby grammar Extensions
private boolean isDubyExtensionsEnabled = SafePropertyAccessor.getBoolean("jruby.duby.enabled", false);
// Should we display extra debug information while parsing?
private boolean isDebug = false;
// whether we should save the end-of-file data as DATA
Expand Down Expand Up @@ -216,8 +214,4 @@ public boolean isSaveData() {
public boolean isInlineSource() {
return inlineSource;
}

public boolean isDubyExtensionsEnabled() {
return isDubyExtensionsEnabled;
}
}
6 changes: 2 additions & 4 deletions src/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ public void reset() {
}

public void allowDubyExtension(ISourcePosition position) {
if (!configuration.isDubyExtensionsEnabled()) {
throw new SyntaxException(PID.DUBY_EXTENSIONS_OFF, position,
lexer.getCurrentLine(), "Duby extensions not configured");
}
throw new SyntaxException(PID.DUBY_EXTENSIONS_OFF, position,
lexer.getCurrentLine(), "Duby extensions not configured");
}

public StaticScope getCurrentScope() {
Expand Down
10 changes: 0 additions & 10 deletions src/org/jruby/runtime/CallbackFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.jruby.runtime.callback.Callback;
import org.jruby.runtime.callback.ReflectionCallbackFactory;
import org.jruby.runtime.callback.InvocationCallbackFactory;
import org.jruby.runtime.callback.DumpingInvocationCallbackFactory;
import org.jruby.util.SafePropertyAccessor;

/**
* Helper class to build Callback method.
Expand Down Expand Up @@ -234,7 +232,6 @@ public abstract class CallbackFactory {
public abstract Callback getFastOptMethod(String method);

private static final boolean reflection;
private static final boolean dumping;


static {
Expand All @@ -244,12 +241,8 @@ public abstract class CallbackFactory {
reflection_ = true;
} else {
reflection_ = RubyInstanceConfig.REFLECTED_HANDLES;
if (SafePropertyAccessor.getProperty("jruby.dump_invocations") != null) {
dumping_ = true;
}
}
reflection = reflection_;
dumping = dumping_;
}

public static CallbackFactory createFactory(Ruby runtime, Class type) {
Expand All @@ -260,10 +253,7 @@ public static CallbackFactory createFactory(Ruby runtime, Class type) {
public static CallbackFactory createFactory(Ruby runtime, Class type, ClassLoader classLoader) {
if (reflection) {
return new ReflectionCallbackFactory(type);
} else if (dumping) {
return new DumpingInvocationCallbackFactory(runtime, type, classLoader);
} else {
// FIXME: No, I don't like it.
return new InvocationCallbackFactory(runtime, type, classLoader);
}
}
Expand Down
26 changes: 23 additions & 3 deletions src/org/jruby/runtime/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ public final class Constants {
public static final String TZDATA_VERSION = "@tzdata.version@";

public static final String DEFAULT_RUBY_VERSION;

/**
* Default size for chained compilation.
*/
public static final int CHAINED_COMPILE_LINE_COUNT_DEFAULT = 500;

/**
* The max count of active methods eligible for JIT-compilation.
*/
public static final int JIT_MAX_METHODS_LIMIT = 4096;

/**
* The max size of JIT-compiled methods (full class size) allowed.
*/
public static final int JIT_MAX_SIZE_LIMIT = 30000;

/**
* The JIT threshold to the specified method invocation count.
*/
public static final int JIT_THRESHOLD = 50;

@Deprecated
public static final String JRUBY_PROPERTIES = "/org/jruby/jruby.properties";
Expand All @@ -64,12 +84,12 @@ public final class Constants {
REVISION = "@jruby.revision@";
String defaultRubyVersion = "@jruby.default.ruby.version@";
if (defaultRubyVersion.equals("1.8")) {
DEFAULT_RUBY_VERSION = "RUBY1_8";
DEFAULT_RUBY_VERSION = "1.8";
} else if (defaultRubyVersion.equals("1.9")) {
DEFAULT_RUBY_VERSION = "RUBY1_9";
DEFAULT_RUBY_VERSION = "1.9";
} else {
System.err.println("invalid version selected in build (\"" + defaultRubyVersion + "\"), using 1.8");
DEFAULT_RUBY_VERSION = "RUBY1_8";
DEFAULT_RUBY_VERSION = "1.8";
}
}

Expand Down
17 changes: 0 additions & 17 deletions src/org/jruby/runtime/MethodFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ public static MethodFactory createFactory(ClassLoader classLoader) {
// if reflection is forced or we've determined that we can't load bytecode, use reflection
if (reflection || !CAN_LOAD_BYTECODE) return new ReflectionMethodFactory();

// if we're dumping invokers to disk, use dumping
if (dumping) return new DumpingInvocationMethodFactory(dumpingPath, classLoader);

// otherwise, generate invokers at runtime
return new InvocationMethodFactory(classLoader);
}
Expand Down Expand Up @@ -262,14 +259,6 @@ public byte[] getBlockCallback19Offline(String method, String file, int line, St
* Use the reflection-based factory.
*/
private static final boolean reflection;
/**
* User the dumping-based factory, which generates .class files as it runs.
*/
private static final boolean dumping;
/**
* The target path for the dumping factory to save the .class files.
*/
private static final String dumpingPath;

static {
boolean reflection_ = false, dumping_ = false;
Expand All @@ -279,13 +268,7 @@ public byte[] getBlockCallback19Offline(String method, String file, int line, St
reflection_ = true;
} else {
reflection_ = RubyInstanceConfig.REFLECTED_HANDLES;
if (SafePropertyAccessor.getProperty("jruby.dump_invocations") != null) {
dumping_ = true;
dumpingPath_ = SafePropertyAccessor.getProperty("jruby.dump_invocations");
}
}
reflection = reflection_;
dumping = dumping_;
dumpingPath = dumpingPath_;
}
}
Loading

0 comments on commit 4a83308

Please sign in to comment.