Skip to content

Commit

Permalink
Update to java.lang.invoke, ASM 4 (prerelease), JSR292-mock 1.6, and …
Browse files Browse the repository at this point in the history
…fix compile failure due to bytecode version.
  • Loading branch information
headius committed Apr 27, 2011
1 parent 56b5c02 commit 4fa52b3
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 51 deletions.
10 changes: 5 additions & 5 deletions build.xml
Expand Up @@ -14,11 +14,11 @@

<property name="shared.lib.dir" value="lib/ruby/site_ruby/shared"/>

<property name="asm.jar" value="${build.lib.dir}/asm-3.3.1.jar"/>
<property name="asm-commons.jar" value="${build.lib.dir}/asm-commons-3.3.1.jar"/>
<property name="asm-util.jar" value="${build.lib.dir}/asm-util-3.3.1.jar"/>
<property name="asm-analysis.jar" value="${build.lib.dir}/asm-analysis-3.3.1.jar"/>
<property name="asm-tree.jar" value="${build.lib.dir}/asm-tree-3.3.1.jar"/>
<property name="asm.jar" value="${build.lib.dir}/asm-${asm.version}.jar"/>
<property name="asm-commons.jar" value="${build.lib.dir}/asm-commons-${asm.version}.jar"/>
<property name="asm-util.jar" value="${build.lib.dir}/asm-util-${asm.version}.jar"/>
<property name="asm-analysis.jar" value="${build.lib.dir}/asm-analysis-${asm.version}.jar"/>
<property name="asm-tree.jar" value="${build.lib.dir}/asm-tree-${asm.version}.jar"/>

<path id="build.classpath">
<fileset dir="${build.lib.dir}" includes="*.jar"/>
Expand Down
Binary file removed build_lib/asm-3.3.1.jar
Binary file not shown.
Binary file added build_lib/asm-4.0.jar
Binary file not shown.
Binary file removed build_lib/asm-analysis-3.3.1.jar
Binary file not shown.
Binary file added build_lib/asm-analysis-4.0.jar
Binary file not shown.
Binary file removed build_lib/asm-commons-3.3.1.jar
Binary file not shown.
Binary file added build_lib/asm-commons-4.0.jar
Binary file not shown.
Binary file removed build_lib/asm-tree-3.3.1.jar
Binary file not shown.
Binary file added build_lib/asm-tree-4.0.jar
Binary file not shown.
Binary file removed build_lib/asm-util-3.3.1.jar
Binary file not shown.
Binary file added build_lib/asm-util-4.0.jar
Binary file not shown.
Binary file modified build_lib/jsr292-mock.jar
Binary file not shown.
1 change: 1 addition & 0 deletions default.build.properties
Expand Up @@ -80,3 +80,4 @@ tzdata.ftp.anonymous.userid=jruby@jruby.org
tzdata.distributed.version=2010k
tzdata.latest.version=2011g
jline.version=1.0
asm.version=4.0
4 changes: 2 additions & 2 deletions nbproject/project.xml
Expand Up @@ -235,7 +235,7 @@
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2">
<compilation-unit>
<package-root>${src.dir}</package-root>
<classpath mode="compile">build_lib/junit.jar:build_lib/jline-1.0.jar:build_lib/jna.jar:build_lib/nailgun-0.7.1.jar:build_lib/joni.jar:build_lib/dynalang-0.3.jar:build_lib/invokedynamic.jar:build_lib/jcodings.jar:build_lib/constantine.jar:build_lib/bytelist.jar:build_lib/jffi.jar:build_lib/yydebug.jar:build_lib/bsf.jar:build_lib/jaffl.jar:build_lib/jsr292-mock.jar:build_lib/jgrapht-jdk1.5.jar:build_lib/jnr-netdb.jar:build_lib/jnr-posix.jar:build_lib/joda-time-1.6.2.jar:build_lib/livetribe-jsr223-2.0.6.jar:build_lib/ant.jar:build_lib/asm-3.3.1.jar:build_lib/asm-analysis-3.3.1.jar:build_lib/asm-commons-3.3.1.jar:build_lib/asm-tree-3.3.1.jar:build_lib/asm-util-3.3.1.jar:build_lib/org.osgi.core-4.2.0.jar:build_lib/snakeyaml-1.8.jar</classpath>
<classpath mode="compile">build_lib/junit.jar:build_lib/jline-1.0.jar:build_lib/jna.jar:build_lib/nailgun-0.7.1.jar:build_lib/joni.jar:build_lib/dynalang-0.3.jar:build_lib/invokedynamic.jar:build_lib/jcodings.jar:build_lib/constantine.jar:build_lib/bytelist.jar:build_lib/jffi.jar:build_lib/yydebug.jar:build_lib/bsf.jar:build_lib/jaffl.jar:build_lib/jsr292-mock.jar:build_lib/jgrapht-jdk1.5.jar:build_lib/jnr-netdb.jar:build_lib/jnr-posix.jar:build_lib/joda-time-1.6.2.jar:build_lib/livetribe-jsr223-2.0.6.jar:build_lib/ant.jar:build_lib/org.osgi.core-4.2.0.jar:build_lib/snakeyaml-1.8.jar:build_lib/asm-4.0.jar:build_lib/asm-analysis-4.0.jar:build_lib/asm-commons-4.0.jar:build_lib/asm-tree-4.0.jar:build_lib/asm-util-4.0.jar</classpath>
<built-to>${jruby.classes.dir}</built-to>
<built-to>${lib.dir}/jruby.jar</built-to>
<javadoc-built-to>docs/api</javadoc-built-to>
Expand All @@ -244,7 +244,7 @@
<compilation-unit>
<package-root>${test.dir}</package-root>
<unit-tests/>
<classpath mode="compile">build_lib/bsf.jar:build/classes/jruby:build_lib/junit.jar:build_lib/joda-time-1.6.2.jar:build_lib/jna.jar:build_lib/bytelist.jar:build_lib/jnr-posix.jar:build_lib/livetribe-jsr223-2.0.6.jar:build_lib/asm-3.3.1.jar:build_lib/jcodings.jar</classpath>
<classpath mode="compile">build_lib/bsf.jar:build/classes/jruby:build_lib/junit.jar:build_lib/joda-time-1.6.2.jar:build_lib/jna.jar:build_lib/bytelist.jar:build_lib/jnr-posix.jar:build_lib/livetribe-jsr223-2.0.6.jar:build_lib/jcodings.jar:build_lib/asm-4.0.jar</classpath>
<built-to>${test.classes.dir}</built-to>
<source-level>1.5</source-level>
</compilation-unit>
Expand Down
6 changes: 5 additions & 1 deletion src/org/jruby/RubyInstanceConfig.java
Expand Up @@ -357,8 +357,12 @@ public LoadService create(Ruby runtime) {

if (specVersion.equals("1.5")) {
JAVA_VERSION = Opcodes.V1_5;
} else {
} else if (specVersion.equals("1.6")) {
JAVA_VERSION = Opcodes.V1_6;
} else if (specVersion.equals("1.7")) {
JAVA_VERSION = Opcodes.V1_7;
} else {
throw new RuntimeException("unsupported Java version: " + specVersion);
}
}

Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.jruby.runtime.CallType;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.invokedynamic.InvokeDynamicSupport;
import static org.jruby.util.CodegenUtils.*;

/**
Expand Down Expand Up @@ -122,6 +123,6 @@ public void invokeDynamic(String name, CompilerCallback receiverCallback, Argume
}

// adapter, tc, recv, args{0,1}, block{0,1}]
method.invokedynamic(p(Object.class), invokeName, signature);
method.invokedynamic(invokeName, signature, InvokeDynamicSupport.bootstrapHandle());
}
}
9 changes: 7 additions & 2 deletions src/org/jruby/compiler/impl/SkinnyMethodAdapter.java
Expand Up @@ -21,6 +21,7 @@
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodHandle;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.TraceMethodVisitor;
Expand Down Expand Up @@ -179,8 +180,8 @@ public void invokeinterface(String arg1, String arg2, String arg3) {
getMethodVisitor().visitMethodInsn(INVOKEINTERFACE, arg1, arg2, arg3);
}

public void invokedynamic(String arg1, String arg2, String arg3) {
getMethodVisitor().visitMethodInsn(INVOKEDYNAMIC, arg1, arg2, arg3);
public void invokedynamic(String arg0, String arg1, MethodHandle arg2, Object... arg3) {
getMethodVisitor().visitInvokeDynamicInsn(arg0, arg1, arg2, arg3);
}

public void aprintln() {
Expand Down Expand Up @@ -870,6 +871,10 @@ public void visitFieldInsn(int arg0, String arg1, String arg2, String arg3) {
public void visitMethodInsn(int arg0, String arg1, String arg2, String arg3) {
getMethodVisitor().visitMethodInsn(arg0, arg1, arg2, arg3);
}

public void visitInvokeDynamicInsn(String arg0, String arg1, MethodHandle arg2, Object... arg3) {
getMethodVisitor().visitInvokeDynamicInsn(arg0, arg1, arg2, arg3);
}

public void visitJumpInsn(int arg0, Label arg1) {
getMethodVisitor().visitJumpInsn(arg0, arg1);
Expand Down
20 changes: 0 additions & 20 deletions src/org/jruby/compiler/impl/StandardASMCompiler.java
Expand Up @@ -177,7 +177,6 @@ public static String getClosure19Signature() {
private CacheCompiler cacheCompiler;

public static final Constructor invDynInvCompilerConstructor;
public static final Method invDynSupportInstaller;

private List<InvokerDescriptor> invokerDescriptors = new ArrayList<InvokerDescriptor>();
private List<BlockCallbackDescriptor> blockCallbackDescriptors = new ArrayList<BlockCallbackDescriptor>();
Expand All @@ -194,14 +193,12 @@ public static String getClosure19Signature() {
Class support =
Class.forName("org.jruby.runtime.invokedynamic.InvokeDynamicSupport");
compilerConstructor = compiler.getConstructor(BaseBodyCompiler.class, SkinnyMethodAdapter.class);
installerMethod = support.getDeclaredMethod("installBytecode", MethodVisitor.class, String.class);
}
} catch (Exception e) {
e.printStackTrace();
// leave it null and fall back on our normal invocation logic
}
invDynInvCompilerConstructor = compilerConstructor;
invDynSupportInstaller = installerMethod;
}

/** Creates a new instance of StandardCompilerContext */
Expand Down Expand Up @@ -606,23 +603,6 @@ private void beginClassInit() {

clinitMethod = new SkinnyMethodAdapter(cv, ACC_PUBLIC | ACC_STATIC, "<clinit>", sig(Void.TYPE), null, null);
clinitMethod.start();

if (invDynSupportInstaller != null) {
// install invokedynamic bootstrapper
// TODO need to abstract this setup behind another compiler interface
try {
invDynSupportInstaller.invoke(null, clinitMethod, getClassname());
} catch (IllegalAccessException ex) {
ex.printStackTrace();
// ignore; we won't use invokedynamic
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
// ignore; we won't use invokedynamic
} catch (InvocationTargetException ex) {
ex.printStackTrace();
// ignore; we won't use invokedynamic
}
}
}

private void endClassInit() {
Expand Down
43 changes: 23 additions & 20 deletions src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
@@ -1,11 +1,12 @@
package org.jruby.runtime.invokedynamic;

import java.dyn.CallSite;
import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
import java.dyn.MutableCallSite;
import java.dyn.NoAccessException;
import java.lang.invoke.CallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jruby.RubyBasicObject;
import org.jruby.RubyClass;
import org.jruby.RubyLocalJumpError;
Expand All @@ -22,10 +23,10 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.CacheEntry;
import org.jruby.util.CodegenUtils;
import org.jruby.util.SafePropertyAccessor;
import static org.jruby.util.CodegenUtils.*;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

@SuppressWarnings("deprecation")
public class InvokeDynamicSupport {
Expand All @@ -48,7 +49,7 @@ public MethodType type() {
}
}

public static CallSite bootstrap(Class caller, String name, MethodType type) {
public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException {
JRubyCallSite site;

if (name == "call") {
Expand All @@ -59,26 +60,26 @@ public static CallSite bootstrap(Class caller, String name, MethodType type) {

MethodType fallbackType = type.insertParameterTypes(0, JRubyCallSite.class);
MethodHandle myFallback = MethodHandles.insertArguments(
findStatic(InvokeDynamicSupport.class, "fallback",
lookup.findStatic(InvokeDynamicSupport.class, "fallback",
fallbackType),
0,
site);
site.setTarget(myFallback);
return site;
}

public static void installBytecode(MethodVisitor method, String classname) {
SkinnyMethodAdapter mv = new SkinnyMethodAdapter(method);
mv.ldc(c(classname));
mv.invokestatic(p(Class.class), "forName", sig(Class.class, params(String.class)));
mv.getstatic(p(InvokeDynamicSupport.class), "BOOTSTRAP", ci(MethodHandle.class));
mv.invokestatic(p(java.dyn.Linkage.class), "registerBootstrapMethod", sig(void.class, Class.class, MethodHandle.class));
public final static MethodType BOOTSTRAP_SIGNATURE = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
public final static String BOOTSTRAP_SIGNATURE_DESC = sig(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);

public static org.objectweb.asm.MethodHandle bootstrapHandle() {
return new org.objectweb.asm.MethodHandle(Opcodes.MH_INVOKESTATIC, p(InvokeDynamicSupport.class), "bootstrap", BOOTSTRAP_SIGNATURE_DESC);
}

private static MethodHandle createGWT(MethodHandle test, MethodHandle target, MethodHandle fallback, CacheEntry entry, JRubyCallSite site) {
if (entry.method.getNativeCall() != null) {
DynamicMethod.NativeCall nativeCall = entry.method.getNativeCall();
Class[] nativeSig = nativeCall.getNativeSignature();
// if enabled, use invokedynamic for ruby to ruby calls
if (SafePropertyAccessor.getBoolean("jruby.compile.invokedynamic.rubyDirect", true) &&
nativeSig.length > 0 &&
AbstractScript.class.isAssignableFrom(nativeSig[0]) &&
Expand All @@ -87,6 +88,7 @@ private static MethodHandle createGWT(MethodHandle test, MethodHandle target, Me
return createRubyGWT(nativeCall, test, fallback, entry, site);
}
} else {
// if enabled, use invokedynamic for ruby to native calls
if (SafePropertyAccessor.getBoolean("jruby.compile.invokedynamic.nativeDirect", true) &&
getArgCount(nativeSig, nativeCall.isStatic()) != -1) {
if (nativeSig.length > 0 && nativeSig[0] == ThreadContext.class && nativeSig[nativeSig.length - 1] != Block.class) {
Expand Down Expand Up @@ -460,9 +462,6 @@ public static IRubyObject retryJumpError(ThreadContext context) {
throw context.getRuntime().newLocalJumpError(RubyLocalJumpError.Reason.RETRY, context.getRuntime().getNil(), "retry outside of rescue not supported");
}

private static final MethodType BOOTSTRAP_TYPE = MethodType.methodType(CallSite.class, Class.class, String.class, MethodType.class);
public static final MethodHandle BOOTSTRAP = findStatic(InvokeDynamicSupport.class, "bootstrap", BOOTSTRAP_TYPE);

private static final MethodHandle GETMETHOD;
static {
MethodHandle getMethod = findStatic(InvokeDynamicSupport.class, "getMethod", MethodType.methodType(DynamicMethod.class, CacheEntry.class));
Expand Down Expand Up @@ -812,14 +811,18 @@ private static MethodHandle dropNameAndArgs(MethodHandle original, int index, in
private static MethodHandle findStatic(Class target, String name, MethodType type) {
try {
return MethodHandles.lookup().findStatic(target, name, type);
} catch (NoAccessException nae) {
} catch (NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
} catch (IllegalAccessException nae) {
throw new RuntimeException(nae);
}
}
private static MethodHandle findVirtual(Class target, String name, MethodType type) {
try {
return MethodHandles.lookup().findVirtual(target, name, type);
} catch (NoAccessException nae) {
} catch (NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
} catch (IllegalAccessException nae) {
throw new RuntimeException(nae);
}
}
Expand Down

0 comments on commit 4fa52b3

Please sign in to comment.