Skip to content

Commit

Permalink
Move more bootstrap to logical homes
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 19, 2023
1 parent ad125ea commit 2364098
Show file tree
Hide file tree
Showing 15 changed files with 973 additions and 887 deletions.
37 changes: 37 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/indy/ArrayBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jruby.ir.targets.indy;

import com.headius.invokebinder.Binder;
import org.jruby.RubyArray;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.specialized.RubyArraySpecialized;

import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class ArrayBootstrap {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();

private static final MethodHandle ARRAY_HANDLE =
Binder
.from(RubyArray.class, ThreadContext.class, IRubyObject[].class)
.invokeStaticQuiet(LOOKUP, Bootstrap.class, "array");

public static CallSite array(MethodHandles.Lookup lookup, String name, MethodType type) {
MethodHandle handle = Binder
.from(type)
.collect(1, IRubyObject[].class)
.invoke(ARRAY_HANDLE);

return new ConstantCallSite(handle);
}

public static RubyArray array(ThreadContext context, IRubyObject[] ary) {
assert ary.length > RubyArraySpecialized.MAX_PACKED_SIZE;
// Bootstrap.array() only dispatches here if ^^ holds
return RubyArray.newArrayNoCopy(context.runtime, ary);
}
}
Loading

0 comments on commit 2364098

Please sign in to comment.