Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f691f6999a55
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3772e64610c2
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 30, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    fae3191 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    b965a15 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    3772e64 View commit details
Showing with 50 additions and 158 deletions.
  1. +0 −130 core/src/main/java/org/jruby/ReifiedRubyObject.java
  2. +50 −28 core/src/main/java/org/jruby/specialized/RubyObjectSpecializer.java
130 changes: 0 additions & 130 deletions core/src/main/java/org/jruby/ReifiedRubyObject.java

This file was deleted.

78 changes: 50 additions & 28 deletions core/src/main/java/org/jruby/specialized/RubyObjectSpecializer.java
Original file line number Diff line number Diff line change
@@ -29,9 +29,9 @@
import me.qmx.jitescript.CodeBlock;
import me.qmx.jitescript.JDKVersion;
import me.qmx.jitescript.JiteClass;
import org.jruby.ReifiedRubyObject;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.builtin.IRubyObject;
@@ -41,6 +41,8 @@
import org.objectweb.asm.Label;
import org.objectweb.asm.tree.LabelNode;

import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@@ -93,30 +95,33 @@ public static ObjectAllocator specializeForVariables(RubyClass klass, Set<String
}

try {
// LMF version not working currently
// MethodHandle allocatorHandle = LOOKUP
// .findConstructor(specialized, MethodType.methodType(void.class, Ruby.class, RubyClass.class))
// .asType(MethodType.methodType(IRubyObject.class, Ruby.class, RubyClass.class));

// MethodType invokeType = MethodType.methodType(IRubyObject.class, Ruby.class, RubyClass.class);
// CallSite allocatorSite = LambdaMetafactory.metafactory(
// lookup,
// "allocate",
// MethodType.methodType(ObjectAllocator.class),
// invokeType,
// allocatorHandle,
// invokeType);
// allocator = (ObjectAllocator) allocatorSite.dynamicInvoker().invokeExact();

MethodHandle allocatorHandle = LOOKUP
.findConstructor(specialized, MethodType.methodType(void.class, Ruby.class, RubyClass.class))
.asType(MethodType.methodType(IRubyObject.class, Ruby.class, RubyClass.class));

ObjectAllocator allocator = (runtime, klazz) -> {
try {
return (IRubyObject) allocatorHandle.invokeExact(runtime, klazz);
} catch (Throwable t) {
Helpers.throwException(t);
return null;
}
};
// LMF version not working currently
// MethodType invokeType = MethodType.methodType(specialized, Ruby.class, RubyClass.class);
// MethodType smaType = MethodType.methodType(IRubyObject.class, Ruby.class, RubyClass.class);
// CallSite allocatorSite = LambdaMetafactory.metafactory(
// LOOKUP,
// "allocate",
// MethodType.methodType(ObjectAllocator.class),
// smaType,
// allocatorHandle,
// invokeType);
//
// ObjectAllocator allocator = (ObjectAllocator) allocatorSite.dynamicInvoker().invokeExact();

// ObjectAllocator allocator = (runtime, klazz) -> {
// try {
// return (IRubyObject) allocatorHandle.invokeExact(runtime, klazz);
// } catch (Throwable t) {
// Helpers.throwException(t);
// return null;
// }
// };

ObjectAllocator allocator = (ObjectAllocator) specialized.getDeclaredClasses()[0].newInstance();

SPECIALIZED_CLASSES.put(size, cna = new ClassAndAllocator(specialized, allocator));
} catch (Throwable t) {
@@ -146,7 +151,7 @@ public static ObjectAllocator specializeForVariables(RubyClass klass, Set<String

private static Class generateInternal(int size, final String clsPath) {
// ensure only one thread will attempt to generate and define the new class
final String baseName = p(ReifiedRubyObject.class);
final String baseName = p(RubyObject.class);

final JiteClass jiteClass = new JiteClass(clsPath, baseName, new String[0]) {{
for (int i = 0; i < size; i++) {
@@ -177,7 +182,7 @@ private static Class generateInternal(int size, final String clsPath) {

aload(0);
iload(1);
invokespecial(p(ReifiedRubyObject.class), "getVariable", sig(Object.class, int.class));
invokespecial(p(RubyObject.class), "getVariable", sig(Object.class, int.class));
areturn();
}});

@@ -193,12 +198,29 @@ private static Class generateInternal(int size, final String clsPath) {
aload(0);
iload(1);
aload(2);
invokespecial(p(ReifiedRubyObject.class), "setVariable", sig(void.class, int.class, Object.class));
invokespecial(p(RubyObject.class), "setVariable", sig(void.class, int.class, Object.class));
voidreturn();
}});

// allocator class
addChildClass(new JiteClass(clsPath + "Allocator", p(Object.class), Helpers.arrayOf(p(ObjectAllocator.class))) {{
defineDefaultConstructor();

defineMethod("allocate", ACC_PUBLIC, sig(IRubyObject.class, Ruby.class, RubyClass.class), new CodeBlock() {{
newobj(clsPath);
dup();
aload(1);
aload(2);
invokespecial(clsPath, "<init>", sig(void.class, Ruby.class, RubyClass.class));
areturn();
}});
}});
}};

return defineClass(jiteClass);
Class specializedClass = defineClass(jiteClass);
defineClass(jiteClass.getChildClasses().get(0));

return specializedClass;
}

private static void genGetSwitch(String clsPath, int size, CodeBlock block, int offsetVar) {