Permalink
Browse files

[1.9] Wire up Method#parameters for AOT compiled methods.

  • Loading branch information...
1 parent 89857bd commit 9c2146ace3c198eb3e862cf47c7af6dd11ae66d4 @headius headius committed with yokolet Jan 8, 2011
View
8 src/org/jruby/RubyJRuby.java
@@ -67,7 +67,9 @@
import java.util.Map;
import org.jruby.ast.MultipleAsgn19Node;
+import org.jruby.internal.runtime.methods.MethodArgs2;
import org.jruby.java.proxies.JavaProxy;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.ExecutionContext;
import org.jruby.runtime.ObjectAllocator;
import static org.jruby.runtime.Visibility.*;
@@ -632,8 +634,10 @@ public static IRubyObject methodArgs(IRubyObject recv) {
RubySymbol opt = runtime.newSymbol("opt");
RubySymbol rest = runtime.newSymbol("rest");
RubySymbol block = runtime.newSymbol("block");
-
- if (method instanceof MethodArgs) {
+
+ if (method instanceof MethodArgs2) {
+ return RuntimeHelpers.parameterListToParameters(runtime, ((MethodArgs2)method).getParameterList(), true);
+ } else if (method instanceof MethodArgs) {
MethodArgs interpMethod = (MethodArgs)method;
ArgsNode args = interpMethod.getArgsNode();
View
9 src/org/jruby/compiler/ASTCompiler.java
@@ -34,8 +34,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.jcodings.CodeRange;
-import org.jcodings.Encoding;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyFloat;
@@ -145,6 +143,7 @@
import org.jruby.internal.runtime.methods.DynamicMethod.NativeCall;
import org.jruby.internal.runtime.methods.InterpretedMethod;
import org.jruby.internal.runtime.methods.JittedMethod;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.BlockBody;
@@ -2083,7 +2082,8 @@ public void call(BodyCompiler context) {
context.defineNewMethod(
defnNode.getName(), defnNode.getArgsNode().getArity().getValue(),
defnNode.getScope(), body, args, null, inspector, isAtRoot,
- defnNode.getPosition().getFile(), defnNode.getPosition().getStartLine());
+ defnNode.getPosition().getFile(), defnNode.getPosition().getStartLine(),
+ RuntimeHelpers.encodeParameterList(argsNode));
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}
@@ -2140,7 +2140,8 @@ public void call(BodyCompiler context) {
context.defineNewMethod(
defsNode.getName(), defsNode.getArgsNode().getArity().getValue(),
defsNode.getScope(), body, args, receiver, inspector, false,
- defsNode.getPosition().getFile(), defsNode.getPosition().getStartLine());
+ defsNode.getPosition().getFile(), defsNode.getPosition().getStartLine(),
+ RuntimeHelpers.encodeParameterList(argsNode));
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}
View
3 src/org/jruby/compiler/BodyCompiler.java
@@ -335,7 +335,8 @@
*/
public void defineNewMethod(String name, int methodArity, StaticScope scope,
CompilerCallback body, CompilerCallback args,
- CompilerCallback receiver, ASTInspector inspector, boolean root, String filename, int line);
+ CompilerCallback receiver, ASTInspector inspector, boolean root,
+ String filename, int line, String parameterDesc);
/**
* Define an alias for a new name to an existing oldName'd method.
View
9 src/org/jruby/compiler/impl/BaseBodyCompiler.java
@@ -44,7 +44,6 @@
import org.jruby.compiler.CompilerCallback;
import org.jruby.compiler.InvocationCompiler;
import org.jruby.compiler.BodyCompiler;
-import org.jruby.compiler.CacheCompiler;
import org.jruby.compiler.FastSwitchType;
import org.jruby.compiler.NotCompilableException;
import org.jruby.compiler.VariableCompiler;
@@ -2569,7 +2568,8 @@ public void issueRetryEvent() {
public void defineNewMethod(String name, int methodArity, StaticScope scope,
CompilerCallback body, CompilerCallback args,
- CompilerCallback receiver, ASTInspector inspector, boolean root, String filename, int line) {
+ 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)) {
@@ -2609,13 +2609,14 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
method.ldc(filename);
method.ldc(line);
method.getstatic(p(CallConfiguration.class), inspector.getCallConfig().name(), ci(CallConfiguration.class));
+ method.ldc(parameterDesc);
if (receiver != null) {
invokeUtilityMethod("defs", sig(IRubyObject.class,
- params(ThreadContext.class, IRubyObject.class, IRubyObject.class, Object.class, String.class, String.class, String.class, int.class, String.class, int.class, CallConfiguration.class)));
+ params(ThreadContext.class, IRubyObject.class, IRubyObject.class, Object.class, String.class, String.class, String.class, int.class, String.class, int.class, CallConfiguration.class, String.class)));
} else {
invokeUtilityMethod("def", sig(IRubyObject.class,
- params(ThreadContext.class, IRubyObject.class, Object.class, String.class, String.class, String.class, int.class, String.class, int.class, CallConfiguration.class)));
+ params(ThreadContext.class, IRubyObject.class, Object.class, String.class, String.class, String.class, int.class, String.class, int.class, CallConfiguration.class, String.class)));
}
script.addInvokerDescriptor(newMethodName, methodArity, scope, inspector.getCallConfig(), filename, line);
View
45 src/org/jruby/internal/runtime/methods/CompiledMethod.java
@@ -39,33 +39,48 @@
import org.jruby.runtime.MethodFactory;
import org.jruby.runtime.PositionAware;
-public abstract class CompiledMethod extends JavaMethod implements Cloneable, PositionAware {
+public abstract class CompiledMethod extends JavaMethod implements Cloneable, PositionAware, MethodArgs2 {
protected Object $scriptObject;
protected ISourcePosition position;
+ protected String[] parameterList;
- public static class LazyCompiledMethod extends DynamicMethod implements Cloneable, PositionAware {
+ public static class LazyCompiledMethod extends DynamicMethod implements Cloneable, PositionAware, MethodArgs2 {
private final String method;
private final Arity arity;
private final StaticScope scope;
private final Object scriptObject;
private MethodFactory factory;
private DynamicMethod compiledMethod;
private final ISourcePosition position;
+ private final String parameterDesc;
+ private final String[] parameterList;
- public LazyCompiledMethod(RubyModule implementationClass, String method, Arity arity,
- Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position, MethodFactory factory) {
+ public LazyCompiledMethod(
+ RubyModule implementationClass,
+ String method,
+ Arity arity,
+ Visibility visibility,
+ StaticScope scope,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ ISourcePosition position,
+ String parameterDesc,
+ MethodFactory factory) {
+
super(implementationClass, visibility, callConfig);
this.method = method;
this.arity = arity;
this.scope = scope;
this.scriptObject = scriptObject;
this.factory = factory;
this.position = position;
+ this.parameterDesc = parameterDesc;
+ this.parameterList = parameterDesc.split(";");
}
private synchronized void initializeMethod() {
if (compiledMethod != null) return;
- compiledMethod = factory.getCompiledMethod(implementationClass, method, arity, visibility, scope, scriptObject, callConfig, position);
+ compiledMethod = factory.getCompiledMethod(implementationClass, method, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc);
factory = null;
}
@@ -210,14 +225,28 @@ public int getLine() {
if (compiledMethod == null) initializeMethod();
return position.getStartLine();
}
+
+ public String[] getParameterList() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
protected CompiledMethod() {}
- protected void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position) {
+ protected void init(
+ RubyModule implementationClass,
+ Arity arity,
+ Visibility visibility,
+ StaticScope staticScope,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ ISourcePosition position,
+ String parameterDesc) {
+
this.$scriptObject = scriptObject;
this.position = position;
+ this.parameterList = parameterDesc.split(";");
super.init(implementationClass, arity, visibility, staticScope, callConfig);
}
@@ -263,4 +292,8 @@ public String getFile() {
public int getLine() {
return position.getStartLine();
}
+
+ public String[] getParameterList() {
+ return parameterList;
+ }
}// SimpleInvocationMethod
View
47 src/org/jruby/internal/runtime/methods/InvocationMethodFactory.java
@@ -189,9 +189,26 @@ public InvocationMethodFactory(ClassLoader classLoader) {
* @see org.jruby.internal.runtime.methods.MethodFactory#getCompiledMethod
*/
public DynamicMethod getCompiledMethodLazily(
- RubyModule implementationClass, String method, Arity arity,
- Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position) {
- return new CompiledMethod.LazyCompiledMethod(implementationClass, method, arity, visibility, scope, scriptObject, callConfig, position,
+ RubyModule implementationClass,
+ String method,
+ Arity arity,
+ Visibility visibility,
+ StaticScope scope,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ ISourcePosition position,
+ String parameterDesc) {
+
+ return new CompiledMethod.LazyCompiledMethod(
+ implementationClass,
+ method,
+ arity,
+ visibility,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc,
new InvocationMethodFactory(classLoader));
}
@@ -201,8 +218,16 @@ public DynamicMethod getCompiledMethodLazily(
* @see org.jruby.internal.runtime.methods.MethodFactory#getCompiledMethod
*/
public DynamicMethod getCompiledMethod(
- RubyModule implementationClass, String method, Arity arity,
- Visibility visibility, StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position) {
+ RubyModule implementationClass,
+ String method,
+ Arity arity,
+ Visibility visibility,
+ StaticScope scope,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ ISourcePosition position,
+ String parameterDesc) {
+
Class scriptClass = scriptObject.getClass();
String typePath = p(scriptClass);
String invokerName = typePath.replaceAll("/", "_") + "Invoker" + method + arity;
@@ -214,14 +239,22 @@ public DynamicMethod getCompiledMethod(
if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
System.err.println("no generated handle in classloader for: " + invokerName);
}
- byte[] invokerBytes = getCompiledMethodOffline(method, typePath, invokerName, arity, scope, callConfig, position.getFile(), position.getStartLine());
+ byte[] invokerBytes = getCompiledMethodOffline(
+ method,
+ typePath,
+ invokerName,
+ arity,
+ scope,
+ callConfig,
+ position.getFile(),
+ position.getStartLine());
generatedClass = endCallWithBytes(invokerBytes, invokerName);
} else if (RubyInstanceConfig.JIT_LOADING_DEBUG) {
System.err.println("found generated handle in classloader: " + invokerName);
}
CompiledMethod compiledMethod = (CompiledMethod)generatedClass.newInstance();
- compiledMethod.init(implementationClass, arity, visibility, scope, scriptObject, callConfig, position);
+ compiledMethod.init(implementationClass, arity, visibility, scope, scriptObject, callConfig, position, parameterDesc);
return compiledMethod;
} catch(Exception e) {
e.printStackTrace();
View
7 src/org/jruby/internal/runtime/methods/JittedMethod.java
@@ -29,6 +29,7 @@
import org.jruby.Ruby;
import org.jruby.RubyModule;
+import org.jruby.ast.ArgsNode;
import org.jruby.ast.executable.Script;
import org.jruby.exceptions.JumpException;
import org.jruby.lexer.yacc.ISourcePosition;
@@ -48,7 +49,7 @@
* method.
*
*/
-public class JittedMethod extends DynamicMethod implements PositionAware {
+public class JittedMethod extends DynamicMethod implements MethodArgs, PositionAware {
private final StaticScope staticScope;
private final Script jitCompiledScript;
private final ISourcePosition position;
@@ -302,6 +303,10 @@ public Arity getArity() {
return arity;
}
+ public ArgsNode getArgsNode() {
+ return realMethod.getArgsNode();
+ }
+
public DynamicMethod dup() {
return new JittedMethod(getImplementationClass(), staticScope, jitCompiledScript, name, callConfig, getVisibility(), arity, position, realMethod);
}
View
29 src/org/jruby/internal/runtime/methods/MethodArgs.java
@@ -1,8 +1,29 @@
/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
+ **** BEGIN LICENSE BLOCK *****
+ * Version: CPL 1.0/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Common Public
+ * License Version 1.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * 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"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the CPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the CPL, the GPL or the LGPL.
+ ***** END LICENSE BLOCK *****/
package org.jruby.internal.runtime.methods;
import org.jruby.ast.ArgsNode;
View
4 src/org/jruby/internal/runtime/methods/ReflectedCompiledMethod.java
@@ -48,9 +48,9 @@
private final ISourcePosition position;
public ReflectedCompiledMethod(RubyModule implementationClass, Arity arity,
- Visibility visibility, StaticScope staticScope, Object scriptObject, Method method, CallConfiguration callConfig, ISourcePosition position) {
+ Visibility visibility, StaticScope staticScope, Object scriptObject, Method method, CallConfiguration callConfig, ISourcePosition position, String parameterDesc) {
super();
- init(implementationClass, arity, visibility, staticScope, scriptObject, callConfig, position);
+ init(implementationClass, arity, visibility, staticScope, scriptObject, callConfig, position, parameterDesc);
this.method = method;
this.position = position;
View
29 src/org/jruby/internal/runtime/methods/ReflectionMethodFactory.java
@@ -64,8 +64,19 @@
*/
public DynamicMethod getCompiledMethodLazily(RubyModule implementationClass,
String methodName, Arity arity, Visibility visibility,
- StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position) {
- return getCompiledMethod(implementationClass, methodName, arity, visibility, scope, scriptObject, callConfig, position);
+ StaticScope scope, Object scriptObject, CallConfiguration callConfig,
+ ISourcePosition position, String parameterDesc) {
+
+ return getCompiledMethod(
+ implementationClass,
+ methodName,
+ arity,
+ visibility,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc);
}
/**
@@ -75,11 +86,21 @@ public DynamicMethod getCompiledMethodLazily(RubyModule implementationClass,
*/
public DynamicMethod getCompiledMethod(RubyModule implementationClass,
String methodName, Arity arity, Visibility visibility,
- StaticScope scope, Object scriptObject, CallConfiguration callConfig, ISourcePosition position) {
+ StaticScope scope, Object scriptObject, CallConfiguration callConfig,
+ ISourcePosition position, String parameterDesc) {
try {
Class scriptClass = scriptObject.getClass();
Method method = scriptClass.getMethod(methodName, scriptClass, ThreadContext.class, IRubyObject.class, IRubyObject[].class, Block.class);
- return new ReflectedCompiledMethod(implementationClass, arity, visibility, scope, scriptObject, method, callConfig, position);
+ return new ReflectedCompiledMethod(
+ implementationClass,
+ arity,
+ visibility,
+ scope,
+ scriptObject,
+ method,
+ callConfig,
+ position,
+ parameterDesc);
} catch (NoSuchMethodException nsme) {
throw new RuntimeException("No method with name " + methodName + " found in " + scriptObject.getClass());
}
View
82 src/org/jruby/javasupport/util/RuntimeHelpers.java
@@ -333,7 +333,7 @@ public static Block createSharedScopeBlock(ThreadContext context, IRubyObject se
}
public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String name, String javaName, String scopeString,
- int arity, String filename, int line, CallConfiguration callConfig) {
+ int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) {
Class compiledClass = scriptObject.getClass();
Ruby runtime = context.getRuntime();
@@ -348,15 +348,16 @@ public static IRubyObject def(ThreadContext context, IRubyObject self, Object sc
DynamicMethod method = constructNormalMethod(
factory, javaName,
name, containingClass, new SimpleSourcePosition(filename, line), arity, scope, visibility, scriptObject,
- callConfig);
+ callConfig,
+ parameterDesc);
addInstanceMethod(containingClass, name, method, visibility,context, runtime);
return runtime.getNil();
}
public static IRubyObject defs(ThreadContext context, IRubyObject self, IRubyObject receiver, Object scriptObject, String name, String javaName, String scopeString,
- int arity, String filename, int line, CallConfiguration callConfig) {
+ int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) {
Class compiledClass = scriptObject.getClass();
Ruby runtime = context.getRuntime();
@@ -365,7 +366,10 @@ public static IRubyObject defs(ThreadContext context, IRubyObject self, IRubyObj
StaticScope scope = createScopeForClass(context, scopeString);
MethodFactory factory = MethodFactory.createFactory(compiledClass.getClassLoader());
- DynamicMethod method = constructSingletonMethod( factory, javaName, rubyClass, new SimpleSourcePosition(filename, line), arity, scope,scriptObject, callConfig);
+ DynamicMethod method = constructSingletonMethod(
+ factory, javaName, rubyClass,
+ new SimpleSourcePosition(filename, line), arity, scope,
+ scriptObject, callConfig, parameterDesc);
rubyClass.addMethod(name, method);
@@ -1649,27 +1653,85 @@ private static void callSingletonMethodHook(IRubyObject receiver, ThreadContext
receiver.callMethod(context, "singleton_method_added", name);
}
- private static DynamicMethod constructNormalMethod( MethodFactory factory, String javaName, String name, RubyModule containingClass, ISourcePosition position, int arity, StaticScope scope, Visibility visibility, Object scriptObject, CallConfiguration callConfig) {
+ private static DynamicMethod constructNormalMethod(
+ MethodFactory factory,
+ String javaName,
+ String name,
+ RubyModule containingClass,
+ ISourcePosition position,
+ int arity,
+ StaticScope scope,
+ Visibility visibility,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ String parameterDesc) {
+
DynamicMethod method;
if (name.equals("initialize") || name.equals("initialize_copy") || visibility == Visibility.MODULE_FUNCTION) {
visibility = Visibility.PRIVATE;
}
if (RubyInstanceConfig.LAZYHANDLES_COMPILE) {
- method = factory.getCompiledMethodLazily(containingClass, javaName, Arity.createArity(arity), visibility, scope, scriptObject, callConfig, position);
+ method = factory.getCompiledMethodLazily(
+ containingClass,
+ javaName,
+ Arity.createArity(arity),
+ visibility,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc);
} else {
- method = factory.getCompiledMethod(containingClass, javaName, Arity.createArity(arity), visibility, scope, scriptObject, callConfig, position);
+ method = factory.getCompiledMethod(
+ containingClass,
+ javaName,
+ Arity.createArity(arity),
+ visibility,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc);
}
return method;
}
- private static DynamicMethod constructSingletonMethod(MethodFactory factory, String javaName, RubyClass rubyClass, ISourcePosition position, int arity, StaticScope scope, Object scriptObject, CallConfiguration callConfig) {
+ private static DynamicMethod constructSingletonMethod(
+ MethodFactory factory,
+ String javaName,
+ RubyClass rubyClass,
+ ISourcePosition position,
+ int arity,
+ StaticScope scope,
+ Object scriptObject,
+ CallConfiguration callConfig,
+ String parameterDesc) {
+
if (RubyInstanceConfig.LAZYHANDLES_COMPILE) {
- return factory.getCompiledMethodLazily(rubyClass, javaName, Arity.createArity(arity), Visibility.PUBLIC, scope, scriptObject, callConfig, position);
+ return factory.getCompiledMethodLazily(
+ rubyClass,
+ javaName,
+ Arity.createArity(arity),
+ Visibility.PUBLIC,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc);
} else {
- return factory.getCompiledMethod(rubyClass, javaName, Arity.createArity(arity), Visibility.PUBLIC, scope, scriptObject, callConfig, position);
+ return factory.getCompiledMethod(
+ rubyClass,
+ javaName,
+ Arity.createArity(arity),
+ Visibility.PUBLIC,
+ scope,
+ scriptObject,
+ callConfig,
+ position,
+ parameterDesc);
}
}
View
6 src/org/jruby/runtime/MethodFactory.java
@@ -103,7 +103,8 @@ public static MethodFactory createFactory(ClassLoader classLoader) {
public abstract DynamicMethod getCompiledMethod(
RubyModule implementationClass, String method,
Arity arity, Visibility visibility, StaticScope scope,
- Object scriptObject, CallConfiguration callConfig, ISourcePosition position);
+ Object scriptObject, CallConfiguration callConfig,
+ ISourcePosition position, String parameterDesc);
/**
* Like getCompiledMethod, but produces the actual bytes for the compiled
@@ -146,7 +147,8 @@ public abstract DynamicMethod getCompiledMethod(
public abstract DynamicMethod getCompiledMethodLazily(
RubyModule implementationClass, String method,
Arity arity, Visibility visibility, StaticScope scope,
- Object scriptObject, CallConfiguration callConfig, ISourcePosition position);
+ Object scriptObject, CallConfiguration callConfig,
+ ISourcePosition position, String parameterDesc);
/**
* Based on a list of annotated Java methods, generate a method handle using

0 comments on commit 9c2146a

Please sign in to comment.