Skip to content
Permalink
Browse files
JIT changes for Symbol encoding issue #2172.
  • Loading branch information
headius committed Dec 10, 2014
1 parent d5b70fd commit 2d62cd2dfbb2baa07f96ce5682655ecd8ffffdc9
@@ -91,6 +91,10 @@ public Object accept(NodeVisitor iVisitor) {
public String getName() {
return name;
}

public Encoding getEncoding() {
return encoding;
}

public List<Node> childNodes() {
return EMPTY_LIST;
@@ -147,17 +147,17 @@ public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] ar

public static final int NUMBERED_SYMBOL_COUNT = 10;

public final RubySymbol getSymbol(ThreadContext context, int i, String name) {return runtimeCache.getSymbol(context, i, name);}
public final RubySymbol getSymbol0(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 0, name);}
public final RubySymbol getSymbol1(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 1, name);}
public final RubySymbol getSymbol2(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 2, name);}
public final RubySymbol getSymbol3(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 3, name);}
public final RubySymbol getSymbol4(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 4, name);}
public final RubySymbol getSymbol5(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 5, name);}
public final RubySymbol getSymbol6(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 6, name);}
public final RubySymbol getSymbol7(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 7, name);}
public final RubySymbol getSymbol8(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 8, name);}
public final RubySymbol getSymbol9(ThreadContext context, String name) {return runtimeCache.getSymbol(context, 9, name);}
public final RubySymbol getSymbol(ThreadContext context, int i, String name, String encoding) {return runtimeCache.getSymbol(context, i, name, encoding);}
public final RubySymbol getSymbol0(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 0, name, encoding);}
public final RubySymbol getSymbol1(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 1, name, encoding);}
public final RubySymbol getSymbol2(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 2, name, encoding);}
public final RubySymbol getSymbol3(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 3, name, encoding);}
public final RubySymbol getSymbol4(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 4, name, encoding);}
public final RubySymbol getSymbol5(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 5, name, encoding);}
public final RubySymbol getSymbol6(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 6, name, encoding);}
public final RubySymbol getSymbol7(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 7, name, encoding);}
public final RubySymbol getSymbol8(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 8, name, encoding);}
public final RubySymbol getSymbol9(ThreadContext context, String name, String encoding) {return runtimeCache.getSymbol(context, 9, name, encoding);}

public static final int NUMBERED_STRING_COUNT = 10;

@@ -1,5 +1,6 @@
package org.jruby.ast.executable;

import org.jcodings.EncodingDB;
import org.jruby.runtime.opto.ConstantCache;
import java.math.BigInteger;
import java.util.Arrays;
@@ -96,10 +97,14 @@ public final CompiledBlockCallback getBlockCallback(Object scriptObject, int ind
return callback;
}

public final RubySymbol getSymbol(ThreadContext context, int index, String name) {
public final RubySymbol getSymbol(ThreadContext context, int index, String name, String encodingName) {
RubySymbol symbol = symbols[index];
if (symbol == null) {
return symbols[index] = context.runtime.newSymbol(name);
symbol = context.runtime.newSymbol(name);
if (encodingName != null) {
symbol.associateEncoding(EncodingDB.getEncodings().get(encodingName.getBytes()).getEncoding());
}
symbols[index] = symbol;
}
return symbol;
}
@@ -3537,7 +3537,8 @@ public void compileSValue(Node node, BodyCompiler context, boolean expr) {
}

public void compileSymbol(Node node, BodyCompiler context, boolean expr) {
context.createNewSymbol(((SymbolNode) node).getName());
SymbolNode symbol = (SymbolNode)node;
context.createNewSymbol(symbol.getName(), symbol.getEncoding());
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}
@@ -168,7 +168,7 @@ public interface BodyCompiler {
/**
* Generate a new "Symbol" value (or fetch the existing one).
*/
public void createNewSymbol(String name);
public void createNewSymbol(String name, Encoding encoding);

public void createObjectArray(Object[] elementArray, ArrayCallback callback);

@@ -28,7 +28,7 @@ public interface CacheCompiler {

public int cacheEncoding(BaseBodyCompiler method, Encoding encoding);

public void cacheSymbol(BaseBodyCompiler method, String symbol);
public void cacheSymbol(BaseBodyCompiler method, String symbol, Encoding encoding);

public void cacheFixnum(BaseBodyCompiler method, long value);

@@ -562,8 +562,8 @@ public void createNewString(ByteList value, int codeRange) {
script.getCacheCompiler().cacheString(this, value, codeRange);
}

public void createNewSymbol(String name) {
script.getCacheCompiler().cacheSymbol(this, name);
public void createNewSymbol(String name, Encoding encoding) {
script.getCacheCompiler().cacheSymbol(this, name, encoding);
}

public void createNewArray(boolean lightweight) {
@@ -158,7 +158,7 @@ public void cacheCallSite(BaseBodyCompiler method, String name, CallType callTyp
callSiteCount++;
}

public void cacheSymbol(BaseBodyCompiler method, String symbol) {
public void cacheSymbol(BaseBodyCompiler method, String symbol, Encoding encoding) {
Integer index = symbolIndices.get(symbol);
if (index == null) {
index = Integer.valueOf(inheritedSymbolCount++);
@@ -169,11 +169,13 @@ public void cacheSymbol(BaseBodyCompiler method, String symbol) {
method.loadThreadContext();
if (index < AbstractScript.NUMBERED_SYMBOL_COUNT) {
method.method.ldc(symbol);
method.method.invokevirtual(scriptCompiler.getClassname(), "getSymbol" + index, sig(RubySymbol.class, ThreadContext.class, String.class));
method.method.ldc(encoding.toString());
method.method.invokevirtual(scriptCompiler.getClassname(), "getSymbol" + index, sig(RubySymbol.class, ThreadContext.class, String.class, String.class));
} else {
method.method.ldc(index.intValue());
method.method.ldc(symbol);
method.method.invokevirtual(scriptCompiler.getClassname(), "getSymbol", sig(RubySymbol.class, ThreadContext.class, int.class, String.class));
method.method.ldc(encoding.toString());
method.method.invokevirtual(scriptCompiler.getClassname(), "getSymbol", sig(RubySymbol.class, ThreadContext.class, int.class, String.class, String.class));
}
}

@@ -421,9 +421,9 @@ public void cacheBigInteger(BaseBodyCompiler method, BigInteger bigint) {
* @param method the method compiler with which bytecode is emitted
* @param symbol the string of the Symbol to cache
*/
public void cacheSymbol(BaseBodyCompiler method, String symbol) {
public void cacheSymbol(BaseBodyCompiler method, String symbol, Encoding encoding) {
if (!Options.INVOKEDYNAMIC_CACHE_LITERALS.load()) {
super.cacheSymbol(method, symbol);
super.cacheSymbol(method, symbol, encoding);
return;
}

@@ -433,7 +433,8 @@ public void cacheSymbol(BaseBodyCompiler method, String symbol) {
"getSymbol",
sig(RubySymbol.class, ThreadContext.class),
InvokeDynamicSupport.getSymbolHandle(),
symbol);
symbol,
encoding.toString());
}

public void cachedGetVariable(BaseBodyCompiler method, String name) {
@@ -119,7 +119,7 @@ public static Handle getRegexpHandle() {
}

public static Handle getSymbolHandle() {
return getBootstrapHandle("getSymbolBootstrap", BOOTSTRAP_STRING_SIG);
return getBootstrapHandle("getSymbolBootstrap", BOOTSTRAP_STRING_STRING_SIG);
}

public static Handle getFixnumHandle() {
@@ -287,13 +287,19 @@ public static CallSite getRegexpBootstrap(Lookup lookup, String name, MethodType
return site;
}

public static CallSite getSymbolBootstrap(Lookup lookup, String name, MethodType type, String symbol) {
public static CallSite getSymbolBootstrap(Lookup lookup, String name, MethodType type, String symbol, String encodingName) {
MutableCallSite site = new MutableCallSite(type);
MethodHandle init = findStatic(
InvokeDynamicSupport.class,
"initSymbol",
methodType(RubySymbol.class, MutableCallSite.class, ThreadContext.class, String.class));
init = insertArguments(init, 2, symbol);
methodType(RubySymbol.class, MutableCallSite.class, ThreadContext.class, String.class, Encoding.class));

Encoding encoding = null;
if (encodingName != null) {
encoding = EncodingDB.getEncodings().get(encodingName.getBytes()).getEncoding();
}

init = insertArguments(init, 2, symbol, encoding);
init = insertArguments(
init,
0,
@@ -841,8 +847,9 @@ public static RubyRegexp initRegexp(MutableCallSite site, ThreadContext context,
return regexp;
}

public static RubySymbol initSymbol(MutableCallSite site, ThreadContext context, String symbol) {
public static RubySymbol initSymbol(MutableCallSite site, ThreadContext context, String symbol, Encoding encoding) {
RubySymbol rubySymbol = context.runtime.newSymbol(symbol);
if (encoding != null) rubySymbol.associateEncoding(encoding);
site.setTarget(dropArguments(constant(RubySymbol.class, rubySymbol), 0, ThreadContext.class));
return rubySymbol;
}

0 comments on commit 2d62cd2

Please sign in to comment.