public static CacheCompiler newCacheCompiler(StandardASMCompiler scriptCompiler) { if (tryIndy) { try { return new InvokeDynamicCacheCompiler(scriptCompiler); } catch (Error e) { tryIndy = false; throw e; } catch (Throwable t) { tryIndy = false; } } return new InheritedCacheCompiler(scriptCompiler); }
public void cacheRubyEncoding(BaseBodyCompiler method, Encoding encoding) { // split into three methods since ByteList depends on two parts in different places cacheEncoding(method, encoding); createRubyEncoding(method); }
public int cacheEncoding(BaseBodyCompiler method, Encoding encoding) { int index = cacheEncodingInternal(encoding); loadEncoding(method.method, index); return index; }
public void cacheConstantBoolean(BaseBodyCompiler method, String constantName) { cacheConstant(method, constantName); method.method.invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class)); }
public void cacheRegexp(BaseBodyCompiler method, ByteList pattern, int options) { method.loadThis(); method.loadThreadContext(); int index = inheritedRegexpCount++; if (index < AbstractScript.NUMBERED_REGEXP_COUNT) { cacheByteList(method, pattern); method.method.ldc(options); method.method.invokevirtual(scriptCompiler.getClassname(), "getRegexp" + index, sig(RubyRegexp.class, ThreadContext.class, ByteList.class, int.class)); } else { method.method.pushInt(index); cacheByteList(method, pattern); method.method.ldc(options); method.method.invokevirtual(scriptCompiler.getClassname(), "getRegexp", sig(RubyRegexp.class, ThreadContext.class, int.class, ByteList.class, int.class)); } }
public void cacheByteList(BaseBodyCompiler method, ByteList contents) { String asString = Helpers.rawBytesToString(contents.bytes()); String key = asString + contents.getEncoding(); Integer index = stringIndices.get(key); if (index == null) { index = Integer.valueOf(inheritedStringCount++); stringEncToString.put(key, asString); stringIndices.put(key, index); stringEncodings.put(key, cacheEncodingInternal(contents.getEncoding())); } method.loadThis(); if (index < AbstractScript.NUMBERED_STRING_COUNT) { method.method.invokevirtual(scriptCompiler.getClassname(), "getByteList" + index, sig(ByteList.class)); } else { method.method.pushInt(index.intValue()); method.method.invokevirtual(scriptCompiler.getClassname(), "getByteList", sig(ByteList.class, int.class)); } }
public void cacheGlobalBoolean(BaseBodyCompiler method, String globalName) { cacheGlobal(method, globalName); method.method.invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class)); }
/** * Cache a Fixnum literal using invokedynamic. * * @param method the method compiler with which bytecode is emitted * @param value the value of the Fixnum */ @Override public void cacheFixnum(BaseBodyCompiler method, long value) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheFixnum(method, value); return; } method.loadThreadContext(); method.method.invokedynamic( "getFixnum", sig(RubyFixnum.class, ThreadContext.class), InvokeDynamicSupport.getFixnumHandle(), value); }
/** * Cache a BigInteger using invokedynamic. Used for Bignum construction * * @param method the method compiler with which bytecode is emitted * @param bigint the BigInteger to cache */ @Override public void cacheBigInteger(BaseBodyCompiler method, BigInteger bigint) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheBigInteger(method, bigint); return; } String asString = bigint.toString(16); method.method.invokedynamic( "getBigInteger", sig(BigInteger.class), InvokeDynamicSupport.getBigIntegerHandle(), asString); }
/** * Cache a Float literal using invokedynamic. * * @param method the method compiler with which bytecode is emitted * @param value the value of the Float */ @Override public void cacheFloat(BaseBodyCompiler method, double value) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheFloat(method, value); return; } method.loadThreadContext(); method.method.invokedynamic( "getFloat", sig(RubyFloat.class, ThreadContext.class), InvokeDynamicSupport.getFloatHandle(), value); }
/** * Cache a constant boolean using invokedynamic. * * This cache uses a java.lang.invoke.SwitchPoint as the invalidation * mechanism in order to avoid the cost of constantly pinging a constant * generation in org.jruby.Ruby. This allows a nearly free constant cache. * * @param method the method compiler with which bytecode is emitted * @param constantName the name of the constant to look up */ @Override public void cacheConstantBoolean(BaseBodyCompiler method, String constantName) { if (!RubyInstanceConfig.INVOKEDYNAMIC_CONSTANTS) { super.cacheConstantBoolean(method, constantName); return; } method.loadThis(); method.loadThreadContext(); method.method.invokedynamic( constantName, sig(boolean.class, AbstractScript.class, ThreadContext.class), InvokeDynamicSupport.getConstantBooleanHandle(), method.getScopeIndex()); }
public void cacheConstantBoolean(BaseBodyCompiler method, String constantName) { cacheConstant(method, constantName); method.method.invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class)); }
public void cacheRegexp(BaseBodyCompiler method, ByteList pattern, int options) { method.loadThis(); method.loadThreadContext(); int index = inheritedRegexpCount++; if (index < AbstractScript.NUMBERED_REGEXP_COUNT) { cacheByteList(method, pattern); method.method.ldc(options); method.method.invokevirtual(scriptCompiler.getClassname(), "getRegexp" + index, sig(RubyRegexp.class, ThreadContext.class, ByteList.class, int.class)); } else { method.method.pushInt(index); cacheByteList(method, pattern); method.method.ldc(options); method.method.invokevirtual(scriptCompiler.getClassname(), "getRegexp", sig(RubyRegexp.class, ThreadContext.class, int.class, ByteList.class, int.class)); } }
public void cacheByteList(BaseBodyCompiler method, ByteList contents) { String asString = Helpers.rawBytesToString(contents.bytes()); String key = asString + contents.getEncoding(); Integer index = stringIndices.get(key); if (index == null) { index = Integer.valueOf(inheritedStringCount++); stringEncToString.put(key, asString); stringIndices.put(key, index); stringEncodings.put(key, cacheEncodingInternal(contents.getEncoding())); } method.loadThis(); if (index < AbstractScript.NUMBERED_STRING_COUNT) { method.method.invokevirtual(scriptCompiler.getClassname(), "getByteList" + index, sig(ByteList.class)); } else { method.method.pushInt(index.intValue()); method.method.invokevirtual(scriptCompiler.getClassname(), "getByteList", sig(ByteList.class, int.class)); } }
public void cacheGlobalBoolean(BaseBodyCompiler method, String globalName) { cacheGlobal(method, globalName); method.method.invokeinterface(p(IRubyObject.class), "isTrue", sig(boolean.class)); }
/** * Cache a Fixnum literal using invokedynamic. * * @param method the method compiler with which bytecode is emitted * @param value the value of the Fixnum */ @Override public void cacheFixnum(BaseBodyCompiler method, long value) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheFixnum(method, value); return; } method.loadThreadContext(); method.method.invokedynamic( "getFixnum", sig(RubyFixnum.class, ThreadContext.class), InvokeDynamicSupport.getFixnumHandle(), value); }
/** * Cache a BigInteger using invokedynamic. Used for Bignum construction * * @param method the method compiler with which bytecode is emitted * @param bigint the BigInteger to cache */ @Override public void cacheBigInteger(BaseBodyCompiler method, BigInteger bigint) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheBigInteger(method, bigint); return; } String asString = bigint.toString(16); method.method.invokedynamic( "getBigInteger", sig(BigInteger.class), InvokeDynamicSupport.getBigIntegerHandle(), asString); }
/** * Cache a Float literal using invokedynamic. * * @param method the method compiler with which bytecode is emitted * @param value the value of the Float */ @Override public void cacheFloat(BaseBodyCompiler method, double value) { if (!RubyInstanceConfig.INVOKEDYNAMIC_LITERALS) { super.cacheFloat(method, value); return; } method.loadThreadContext(); method.method.invokedynamic( "getFloat", sig(RubyFloat.class, ThreadContext.class), InvokeDynamicSupport.getFloatHandle(), value); }
/** * Cache a constant boolean using invokedynamic. * * This cache uses a java.lang.invoke.SwitchPoint as the invalidation * mechanism in order to avoid the cost of constantly pinging a constant * generation in org.jruby.Ruby. This allows a nearly free constant cache. * * @param method the method compiler with which bytecode is emitted * @param constantName the name of the constant to look up */ @Override public void cacheConstantBoolean(BaseBodyCompiler method, String constantName) { if (!RubyInstanceConfig.INVOKEDYNAMIC_CONSTANTS) { super.cacheConstantBoolean(method, constantName); return; } method.loadThis(); method.loadThreadContext(); method.method.invokedynamic( constantName, sig(boolean.class, AbstractScript.class, ThreadContext.class), InvokeDynamicSupport.getConstantBooleanHandle(), method.getScopeIndex()); }
public void cacheRubyEncoding(BaseBodyCompiler method, Encoding encoding) { // split into three methods since ByteList depends on two parts in different places cacheEncoding(method, encoding); createRubyEncoding(method); }