Skip to content

Commit

Permalink
Showing 21 changed files with 45 additions and 190 deletions.
7 changes: 1 addition & 6 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1215,11 +1215,6 @@ public final void addMethodAtBootTimeOnly(String name, DynamicMethod method) {
method.setImplementationClass(methodLocation);
}

// if method does not have a name already, set it
if (method.getName() == null) {
method.setName(name);
}

methodLocation.getMethodsForWrite().put(name, method);

getRuntime().addProfiledMethod(name, method);
@@ -2048,7 +2043,7 @@ private DynamicMethod createProcMethod(String name, Visibility visibility, RubyP
// a method definition.
block.getBody().getStaticScope().makeArgumentScope();

return new ProcMethod(this, proc, visibility);
return new ProcMethod(this, proc, visibility, name);
}

public IRubyObject name() {
17 changes: 9 additions & 8 deletions core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -225,8 +225,9 @@ public static RubyClass newInstance(IRubyObject recv, IRubyObject[] args, Block
final String memberName = args[i].asJavaString();
// if we are storing a name as well, index is one too high for values
final int index = (name == null && !nilName) ? i : i - 1;
newStruct.addMethod(memberName, new Accessor(newStruct, index));
newStruct.addMethod(memberName + '=', new Mutator(newStruct, index));
newStruct.addMethod(memberName, new Accessor(newStruct, memberName, index));
String nameAsgn = memberName + '=';
newStruct.addMethod(nameAsgn, new Mutator(newStruct, nameAsgn, index));
}

if (block.isGiven()) {
@@ -765,8 +766,8 @@ public IRubyObject initialize_copy(IRubyObject arg) {
private static class Accessor extends DynamicMethod {
private final int index;

public Accessor(RubyClass newStruct, int index) {
super(newStruct, Visibility.PUBLIC);
public Accessor(RubyClass newStruct, String name, int index) {
super(newStruct, Visibility.PUBLIC, name);
this.index = index;
}

@@ -783,15 +784,15 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

@Override
public DynamicMethod dup() {
return new Accessor((RubyClass) getImplementationClass(), index);
return new Accessor((RubyClass) getImplementationClass(), name, index);
}
}

private static class Mutator extends DynamicMethod {
private final int index;

public Mutator(RubyClass newStruct, int index) {
super(newStruct, Visibility.PUBLIC);
public Mutator(RubyClass newStruct, String name, int index) {
super(newStruct, Visibility.PUBLIC, name);
this.index = index;
}

@@ -808,7 +809,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

@Override
public DynamicMethod dup() {
return new Accessor((RubyClass) getImplementationClass(), index);
return new Mutator((RubyClass) getImplementationClass(), name, index);
}
}

1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ext/ffi/AbstractInvoker.java
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ protected AbstractInvoker(Ruby runtime, RubyClass klass, int arity, MemoryIO io)
public IRubyObject attach(ThreadContext context, IRubyObject obj, IRubyObject methodName) {

DynamicMethod m = createDynamicMethod(obj.getSingletonClass());
m.setName(methodName.asJavaString());
obj.getSingletonClass().addMethod(methodName.asJavaString(), m);
if (obj instanceof RubyModule) {
((RubyModule) obj).addMethod(methodName.asJavaString(), m);
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ext/ffi/Pointer.java
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public boolean isKindOf(IRubyObject obj, RubyModule type) {
Pointer nullPointer = new Pointer(runtime, pointerClass, new NullMemoryIO(runtime));
pointerClass.setConstant("NULL", nullPointer);

runtime.getNilClass().addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer));
runtime.getNilClass().addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer, "to_ptr"));

return pointerClass;
}
@@ -197,8 +197,8 @@ private static final class NilToPointerMethod extends DynamicMethod {
private static final Arity ARITY = Arity.NO_ARGUMENTS;
private final Pointer nullPointer;

private NilToPointerMethod(RubyModule implementationClass, Pointer nullPointer) {
super(implementationClass, Visibility.PUBLIC);
private NilToPointerMethod(RubyModule implementationClass, Pointer nullPointer, String name) {
super(implementationClass, Visibility.PUBLIC, name);
this.nullPointer = nullPointer;
}

4 changes: 1 addition & 3 deletions core/src/main/java/org/jruby/ext/ffi/jffi/DefaultMethod.java
Original file line number Diff line number Diff line change
@@ -23,10 +23,9 @@ public class DefaultMethod extends DynamicMethod implements CacheableMethod {
protected final Arity arity;
protected final Function function;


public DefaultMethod(RubyModule implementationClass, Function function,
Signature signature, NativeInvoker defaultInvoker) {
super(implementationClass, Visibility.PUBLIC);
super(implementationClass, Visibility.PUBLIC, defaultInvoker.getName());
this.arity = Arity.fixed(signature.getParameterCount());
this.function = function;
this.defaultInvoker = defaultInvoker;
@@ -83,7 +82,6 @@ private synchronized NativeInvoker tryCompilation() {

NativeInvoker invoker = getJITHandle().compile(getImplementationClass(), function, signature, getName());
if (invoker != null) {
invoker.setName(getName());
compiledInvoker = invoker;
getImplementationClass().invalidateCacheDescendants();
return compiledInvoker;
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ abstract public class NativeInvoker extends DynamicMethod {


public NativeInvoker(RubyModule implementationClass, com.kenai.jffi.Function function, Signature signature) {
super(implementationClass, Visibility.PUBLIC);
super(implementationClass, Visibility.PUBLIC, "ffi"+function.getFunctionAddress());
this.arity = Arity.fixed(signature.getParameterCount());
this.function = function;
this.signature = signature;
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public class AliasMethod extends DynamicMethod {
private String oldName;

public AliasMethod(RubyModule implementationClass, DynamicMethod oldMethod, String oldName) {
super(implementationClass, oldMethod.getVisibility());
super(implementationClass, oldMethod.getVisibility(), oldName);

this.oldName = oldName;
this.oldMethod = oldMethod;
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public abstract class DelegatingDynamicMethod extends DynamicMethod {
protected final DynamicMethod delegate;

public DelegatingDynamicMethod(DynamicMethod delegate) {
super(delegate.getImplementationClass(), delegate.getVisibility());
super(delegate.getImplementationClass(), delegate.getVisibility(), delegate.getName());
this.delegate = delegate;
}

@@ -168,11 +168,6 @@ public String getName() {
return delegate.getName(); //To change body of overridden methods use File | Settings | File Templates.
}

@Override
public void setName(String name) {
delegate.setName(name); //To change body of overridden methods use File | Settings | File Templates.
}

@Override
public boolean isNotImplemented() {
return delegate.isNotImplemented(); //To change body of overridden methods use File | Settings | File Templates.
Original file line number Diff line number Diff line change
@@ -65,26 +65,13 @@ public abstract class DynamicMethod {
/** Flags for builtin, notimpl, etc */
protected byte flags;
/** The simple, base name this method was defined under. May be null.*/
protected String name;
protected final String name;
/** An arbitrarily-typed "method handle" for use by compilers and call sites */
protected Object handle;

private static final int BUILTIN_FLAG = 0x1;
private static final int NOTIMPL_FLAG = 0x2;

/**
* Base constructor for dynamic method handles.
*
* @param implementationClass The class to which this method will be
* immediately bound
* @param visibility The visibility assigned to this method
* pre/post invocation logic.
*/
protected DynamicMethod(RubyModule implementationClass, Visibility visibility) {
assert implementationClass != null;
init(implementationClass, visibility);
}

/**
* Base constructor for dynamic method handles with names.
*
@@ -94,15 +81,19 @@ protected DynamicMethod(RubyModule implementationClass, Visibility visibility) {
* @param name The simple name of this method
*/
protected DynamicMethod(RubyModule implementationClass, Visibility visibility, String name) {
this(implementationClass, visibility);
assert implementationClass != null;
assert name != null;
this.name = name;
init(implementationClass, visibility);
}

/**
* A no-arg constructor used only by the UndefinedMethod subclass and
* CompiledMethod handles. instanceof assertions make sure this is so.
*/
protected DynamicMethod() {
protected DynamicMethod(String name) {
this.visibility = (byte) Visibility.PUBLIC.ordinal();
this.name = name;
// assert (this instanceof UndefinedMethod ||
// this instanceof CompiledMethod ||
// this instanceof );
@@ -491,15 +482,6 @@ public String getName() {
return name;
}

/**
* Set the base name for this method.
*
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* Get the "handle" associated with this DynamicMethod.
*
@@ -568,4 +550,12 @@ public CallConfiguration getCallConfig() {
@Deprecated
public void setCallConfig(CallConfiguration callConfig) {
}

/**
* @deprecated Use {@link DynamicMethod#DynamicMethod(RubyModule, Visibility, String)}
*/
@Deprecated
protected DynamicMethod(RubyModule implementationClass, Visibility visibility) {
this(implementationClass, visibility, "(anonymous)");
}
}
Original file line number Diff line number Diff line change
@@ -76,31 +76,7 @@ public class HandleMethod extends DynamicMethod implements MethodArgs2, Cloneabl
public HandleMethod(
RubyModule implementationClass,
Visibility visibility,
long encodedSignature,
boolean builtin,
boolean notImplemented,
String parameterDesc,
final int min,
final int max,
final Callable<MethodHandle>... makers) {

super(implementationClass, visibility);
this.signature = Signature.decode(encodedSignature);
this.builtin = builtin;
this.notImplemented = notImplemented;
this.parameterDesc = parameterDesc;
this.min = min;
this.max = max;
this.maker0 = makers[0];
this.maker1 = makers[1];
this.maker2 = makers[2];
this.maker3 = makers[3];
this.maker4 = makers[4];
}

public HandleMethod(
RubyModule implementationClass,
Visibility visibility,
String name,
long encodedSignature,
boolean builtin,
boolean notImplemented,
@@ -113,7 +89,7 @@ public HandleMethod(
final Callable<MethodHandle> maker3,
final Callable<MethodHandle> maker4) {

super(implementationClass, visibility);
super(implementationClass, visibility, name);
this.signature = Signature.decode(encodedSignature);
this.builtin = builtin;
this.notImplemented = notImplemented;
@@ -284,7 +260,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz

@Override
public DynamicMethod dup() {
return new HandleMethod(implementationClass, getVisibility(), signature.encode(), builtin, notImplemented, parameterDesc, min, max, maker0, maker1, maker2, maker3, maker4);
return new HandleMethod(implementationClass, getVisibility(), name, signature.encode(), builtin, notImplemented, parameterDesc, min, max, maker0, maker1, maker2, maker3, maker4);
}

@Override
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ public DynamicMethod getAnnotatedMethod(final RubyModule implementationClass, fi
return new HandleMethod(
implementationClass,
desc1.anno.visibility(),
desc1.name,
(min == max) ?
org.jruby.runtime.Signature.from(min, 0, 0, 0, 0, org.jruby.runtime.Signature.Rest.NONE, -1).encode() :
org.jruby.runtime.Signature.OPTIONAL.encode(),
Original file line number Diff line number Diff line change
@@ -92,8 +92,6 @@ public JavaMethod(RubyModule implementationClass, Visibility visibility, String
super(implementationClass, visibility, name);
}

protected JavaMethod() {}

public void init(RubyModule implementationClass, Arity arity, Visibility visibility, StaticScope staticScope) {
this.staticScope = staticScope;
setArity(arity);
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public class MethodMethod extends DynamicMethod {
*/
public MethodMethod(RubyModule implementationClass, RubyUnboundMethod method, Visibility visibility) {
// FIXME: set up a CallConfiguration for this
super(implementationClass, visibility);
super(implementationClass, visibility, method.getMethodName());
this.method = method;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ public class NullMethod extends DynamicMethod {
* Constructor for the one NullMethod instance.
*/
private NullMethod() {
super("null");
}

/**
Original file line number Diff line number Diff line change
@@ -53,9 +53,9 @@ public class ProcMethod extends DynamicMethod implements PositionAware, IRMethod
* Constructor for ProcMethod.
* @param visibility
*/
public ProcMethod(RubyModule implementationClass, RubyProc proc, Visibility visibility) {
public ProcMethod(RubyModule implementationClass, RubyProc proc, Visibility visibility, String name) {
// FIXME: set up a call configuration for this
super(implementationClass, visibility);
super(implementationClass, visibility, name);
this.proc = proc;
}

@@ -64,7 +64,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule klaz
}

public DynamicMethod dup() {
return new ProcMethod(getImplementationClass(), proc, getVisibility());
return new ProcMethod(getImplementationClass(), proc, getVisibility(), name);
}

// TODO: Push isSame up to DynamicMethod to simplify general equality
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ public class UndefinedMethod extends DynamicMethod {
* Constructor for the one UndefinedMethod instance.
*/
private UndefinedMethod() {
super("(undefined)");
}

/**
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public class WrapperMethod extends DynamicMethod {
* @param visibility
*/
public WrapperMethod(RubyModule implementationClass, DynamicMethod method, Visibility visibility) {
super(implementationClass, visibility);
super(implementationClass, visibility, method.getName() );
this.method = method;
}

52 changes: 0 additions & 52 deletions core/src/main/java/org/jruby/java/util/BlankSlateWrapper.java

This file was deleted.

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/Java.java
Original file line number Diff line number Diff line change
@@ -1092,7 +1092,7 @@ public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModul
static final class ProcToInterface extends org.jruby.internal.runtime.methods.DynamicMethod {

ProcToInterface(final RubyClass singletonClass) {
super(singletonClass, PUBLIC);
super(singletonClass, PUBLIC, "call");
}

@Override // method_missing impl :
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -383,6 +383,7 @@ private static class MethodMissingMethod extends DynamicMethod {
private final Visibility lastVisibility;

public MethodMissingMethod(DynamicMethod delegate, Visibility lastVisibility, CallType lastCallStatus) {
super(delegate.getImplementationClass(), lastVisibility, delegate.getName());
this.delegate = delegate;
this.lastCallStatus = lastCallStatus;
this.lastVisibility = lastVisibility;

0 comments on commit 577d13a

Please sign in to comment.