Skip to content

Commit

Permalink
Merge branch 'jruby-1_7'
Browse files Browse the repository at this point in the history
* jruby-1_7: (40 commits)
  keep the provider in a local while terminating + missing @OverRide
  un-used imports
  close (URLClassLoader's) resources on JRubyClassLoader#tearDown on Java 7+
  only re-wrap non-runtime exceptions in getJDBCDriverUnloader
  depreacate JRubyClassLoader's getJDBCDriverUnloader (its un-used - but still should not be part of public API)
  review the WeakHashSet impl + add missing (useful) methods: equals, toString, ...
  correct javadoc and generix-ize the guts of WeakValued map-like collections
  JavaMethod's (redundant) arityValue field is only used in ReflectedJavaMethod
  Add test for packages of classes in nested JARs
  Define packages for classes in nested JARs
  fixes expand_path on relative reference and inside uri:classloader: as CWD
  detect uri-like paths better for File.expand_path
  fixes commandline execution of internal java -cp ... org.jruby.Main command
  get classloader root url right without an trailing slash
  added nested IsolatedScriptingContainer via jruby-mains test
  make it 1.8 compatible
  you can not close classloaders on jdk6
  extracted the classloader to uri-like path into helper class
  have no side effects when creating instance of IsolatedScriptingContainer
  remove some import jul left-overs + finalize accessibleObject() on JavaMethod
  ...

Conflicts:
	core/src/main/java/org/jruby/Ruby.java
	core/src/main/java/org/jruby/RubyInstanceConfig.java
	core/src/main/java/org/jruby/compiler/JITCompiler.java
	core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
	core/src/main/java/org/jruby/embed/ScriptingContainer.java
	core/src/main/java/org/jruby/internal/runtime/methods/JavaMethod.java
	core/src/main/java/org/jruby/internal/runtime/methods/ReflectedJavaMethod.java
	core/src/main/java/org/jruby/javasupport/JavaEmbedUtils.java
	core/src/main/java/org/jruby/util/ClassCache.java
	core/src/main/java/org/jruby/util/JRubyClassLoader.java
	core/src/main/java/org/jruby/util/cli/Options.java
	core/src/main/ruby/jruby/kernel19/kernel.rb
	lib/ruby/1.9/date.rb
	lib/ruby/shared/rubygems/defaults/jruby.rb
	maven/jruby-complete/src/it/integrity/pom.xml
	maven/jruby-complete/src/templates/osgi_many_bundles_with_embedded_gems/test/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
	maven/jruby/src/it/runnable/spec/one_spec.rb
	maven/jruby/src/templates/osgi_all_inclusive/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
	test/test_file.rb
	test/test_load.rb
  • Loading branch information
kares committed Jul 25, 2015
2 parents 0be4796 + 83c47ba commit 449377c
Show file tree
Hide file tree
Showing 36 changed files with 933 additions and 342 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class RubyDir extends RubyObject {

private final static Encoding UTF8 = UTF8Encoding.INSTANCE;

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^(uri|jar|file|classpath):([^:]*:)?//?.*");

public RubyDir(Ruby runtime, RubyClass type) {
super(runtime, type);
}
Expand Down Expand Up @@ -308,7 +310,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
if (PROTOCOL_PATTERN.matcher(adjustedPath).matches()) {
realPath = adjustedPath;
}
else {
Expand Down
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1540,16 +1540,18 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// argument is relative.
if (args.length == 2 && !args[1].isNil()) {
// TODO maybe combine this with get_path method
if ((args[1] instanceof RubyString) && args[1].asJavaString().startsWith("uri:")) {
cwd = args[1].asJavaString();
String path = args[1].toString();
if (path.startsWith("uri:")) {
cwd = path;
} else {
cwd = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[1])).getUnicodeValue();

// Handle ~user paths.
if (expandUser) {
cwd = expandUserPath(context, cwd, true);
}


// TODO try to treat all uri-like paths alike
String[] cwdURIParts = splitURI(cwd);
if (uriParts == null && cwdURIParts != null) {
uriParts = cwdURIParts;
Expand All @@ -1566,7 +1568,8 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
// If the path isn't absolute, then prepend the current working
// directory to the path.
if (!startsWithSlashNotOnWindows && !startsWithDriveLetterOnWindows(cwd)) {
cwd = new File(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
if ("".equals(cwd)) cwd = ".";
cwd = JRubyFile.create(runtime.getCurrentDirectory(), cwd).getAbsolutePath();
}
}
} else {
Expand Down
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -70,8 +68,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -1756,8 +1752,6 @@ public boolean shouldPrecompileAll() {

public static final boolean JIT_CACHE_ENABLED = Options.JIT_CACHE.load();

public static final String JIT_CODE_CACHE = Options.JIT_CODECACHE.load();

public static final boolean REFLECTED_HANDLES = Options.REFLECTED_HANDLES.load();

public static final boolean NO_UNWRAP_PROCESS_STREAMS = Options.PROCESS_NOUNWRAP.load();
Expand Down Expand Up @@ -1947,4 +1941,5 @@ public boolean isCextEnabled() {
return false;
}

@Deprecated public static final String JIT_CODE_CACHE = "";
}
28 changes: 14 additions & 14 deletions core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* Copyright (C) 2006-2008 Charles O Nutter <headius@headius.com>
* Copyright (C) 2008 Thomas E Enebo <enebo@acm.org>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
Expand Down Expand Up @@ -84,10 +84,10 @@ public static class JITCounts {

private final JITCounts counts = new JITCounts();
private final ExecutorService executor;

private final Ruby runtime;
private final RubyInstanceConfig config;

public JITCompiler(Ruby runtime) {
this.runtime = runtime;
this.config = runtime.getInstanceConfig();
Expand Down Expand Up @@ -120,19 +120,19 @@ public long getCompileTime() {
public long getAbandonCount() {
return counts.abandonCount.get();
}

public long getCodeSize() {
return counts.codeSize.get();
}

public long getAverageCodeSize() {
return counts.averageCodeSize.get();
}

public long getAverageCompileTime() {
return counts.averageCompileTime.get() / 1000;
}

public long getLargestCodeSize() {
return counts.largestCodeSize.get();
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public static String getHashForBytes(byte[] bytes) {
throw new RuntimeException(nsae);
}
}

public static class JITClassGenerator {
public JITClassGenerator(String className, String methodName, String key, Ruby ruby, MixedModeIRMethod method, JVMVisitor visitor) {
this.packageName = JITCompiler.RUBY_JIT_PREFIX;
Expand All @@ -345,7 +345,7 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
// Also, invokedynamic forces us to make jitted bytecode unique to each runtime, since the call sites cache
// at class level rather than at our runtime level. This makes it impossible to share jitted bytecode
// across runtimes.

digestString = key + Math.abs(ruby.hashCode());
} else {
digestString = key;
Expand All @@ -356,11 +356,11 @@ public JITClassGenerator(String className, String methodName, String key, Ruby r
this.method = method;
this.visitor = visitor;
}

@SuppressWarnings("unchecked")
protected void compile() {
if (bytecode != null) return;

// Time the compilation
long start = System.nanoTime();

Expand Down Expand Up @@ -395,7 +395,7 @@ void updateCounters(JITCounts counts) {
public void generate() {
compile();
}

public byte[] bytecode() {
return bytecode;
}
Expand Down Expand Up @@ -429,15 +429,15 @@ static void log(RubyModule implementationClass, String file, int line, String na
name = isBlock ? "" : "." + name;

StringBuilder builder = new StringBuilder(message + ":" + className + name + " at " + file + ":" + line);

if (reason.length > 0) {
builder.append(" because of: \"");
for (int i = 0; i < reason.length; i++) {
builder.append(reason[i]);
}
builder.append('"');
}

LOG.info(builder.toString());
}
}
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
/**
* the IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* in such a way that it uses only resources which can be reached with classloader.
*
*
* GEM_HOME is uri:classloader://META-INF/jruby.home/lib/ruby/gems/shared
* GEM_PATH is uri:classloader://
* JARS_HOME is uri:classloader://jars
*
*
* but whenever you want to set them via {@link #setEnvironment(Map)} this will be honored.
*
*
* it also comes with OSGi support which allows to add a bundle to LOAD_PATH or GEM_PATH.
*/
public class IsolatedScriptingContainer extends ScriptingContainer {

private static final String JRUBY_HOME = "/META-INF/jruby.home";
private static final String URI_CLASSLOADER = "uri:classloader:/";

public IsolatedScriptingContainer()
{
Expand Down Expand Up @@ -48,20 +48,20 @@ public IsolatedScriptingContainer( LocalContextScope scope,
{
super(scope, behavior, lazy);

setLoadPaths( Arrays.asList( "uri:classloader:" ) );
setLoadPaths( Arrays.asList( URI_CLASSLOADER ) );

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
setEnvironment(null);
}

@Override
public void setEnvironment(Map environment) {
if (environment == null || !environment.containsKey("GEM_PATH")
|| !environment.containsKey("GEM_HOME")|| !environment.containsKey("JARS_HOME")) {
if (environment == null || !environment.containsKey("GEM_PATH")
|| !environment.containsKey("GEM_HOME") || !environment.containsKey("JARS_HOME")) {
Map<String,String> env = environment == null ? new HashMap<String,String>() : new HashMap<String,String>(environment);
if (!env.containsKey("GEM_PATH")) env.put("GEM_PATH", "uri:classloader://");
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", "uri:classloader://");
if (!env.containsKey("JARS_HOME")) env.put("JARS_HOME", "uri:classloader://jars");
if (!env.containsKey("GEM_PATH")) env.put("GEM_PATH", URI_CLASSLOADER);
if (!env.containsKey("GEM_HOME")) env.put("GEM_HOME", URI_CLASSLOADER);
if (!env.containsKey("JARS_HOME")) env.put("JARS_HOME", URI_CLASSLOADER + "jars");
super.setEnvironment(env);
}
else {
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static LocalContextProvider getProviderInstance(LocalContextScope scope, LocalVa
return SingletonLocalContextProvider.getProvider(behavior, lazy);
}
}

private void initRubyInstanceConfig() throws RaiseException {
String home = SystemPropertyCatcher.findJRubyHome(this);
if (home != null) {
Expand Down Expand Up @@ -1856,14 +1856,15 @@ public PrintStream getErr() {
* @since JRuby 1.5.0
*/
public void terminate() {
if (getProvider().isRuntimeInitialized()) {
getProvider().getRuntime().tearDown(false);
LocalContextProvider provider = getProvider();
if (provider.isRuntimeInitialized()) {
provider.getRuntime().tearDown(false);
try {
getProvider().getRuntime().getJRubyClassLoader().close();
}
catch(IOException weTriedIt){}
}
getProvider().terminate();
provider.terminate();
}

/**
Expand All @@ -1876,6 +1877,7 @@ public void terminate() {
*
* @since JRuby 1.6.0
*/
@Override
public void finalize() throws Throwable {
super.finalize();
// singleton containers share global runtime, and should not tear it down
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public abstract class JavaMethod extends DynamicMethod implements Cloneable, Met
private String[] parameterList;
private CallConfiguration callerRequirement = CallConfiguration.FrameNoneScopeNone;

private static String[] ONE_REQ = new String[] { "q" };
private static String[] TWO_REQ = new String[] { "q", "q" };
private static String[] THREE_REQ = new String[] { "q", "q", "q" };
private static final String[] ONE_REQ = new String[] { "q" };
private static final String[] TWO_REQ = new String[] { "q", "q" };
private static final String[] THREE_REQ = new String[] { "q", "q", "q" };

public static final Class[][] METHODS = {
{JavaMethodZero.class, JavaMethodZeroOrOne.class, JavaMethodZeroOrOneOrTwo.class, JavaMethodZeroOrOneOrTwoOrThree.class},
Expand Down Expand Up @@ -94,7 +94,7 @@ protected JavaMethod() {}

public void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope, CallConfiguration callConfig) {
this.staticScope = staticScope;
this.arity = arity;
setArity(arity);
super.init(implementationClass, visibility, callConfig);
}

Expand Down
Loading

0 comments on commit 449377c

Please sign in to comment.