< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java

Print this page

        

*** 24,36 **** */ package com.sun.tools.javac.jvm; import com.sun.tools.javac.code.*; ! import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.comp.Resolve; - import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.*; --- 24,35 ---- */ package com.sun.tools.javac.jvm; import com.sun.tools.javac.code.*; ! import com.sun.tools.javac.comp.ConstFold; import com.sun.tools.javac.comp.Resolve; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.*;
*** 222,232 **** return gen.getItems().makeStackItem(syms.stringType); } private JCDiagnostic.DiagnosticPosition newStringBuilder(JCTree tree) { JCDiagnostic.DiagnosticPosition pos = tree.pos(); ! gen.getCode().emitop2(new_, gen.makeRef(pos, syms.stringBuilderType), syms.stringBuilderType); gen.getCode().emitop0(dup); gen.callMethod(pos, syms.stringBuilderType, names.init, List.nil(), false); return pos; } --- 221,231 ---- return gen.getItems().makeStackItem(syms.stringType); } private JCDiagnostic.DiagnosticPosition newStringBuilder(JCTree tree) { JCDiagnostic.DiagnosticPosition pos = tree.pos(); ! gen.getCode().emitop2(new_, gen.makeRef(pos, syms.stringBuilderType)); gen.getCode().emitop0(dup); gen.callMethod(pos, syms.stringBuilderType, names.init, List.nil(), false); return pos; }
*** 365,375 **** int prevPos = make.pos; try { make.at(pos); ! List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType, syms.stringType, syms.methodTypeType); Symbol bsm = rs.resolveInternalMethod(pos, gen.getAttrEnv(), --- 364,374 ---- int prevPos = make.pos; try { make.at(pos); ! List<Type> bsm_staticArgs = List.of(syms.methodHandlesLookupType, syms.stringType, syms.methodTypeType); Symbol bsm = rs.resolveInternalMethod(pos, gen.getAttrEnv(),
*** 378,390 **** bsm_staticArgs, null); Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcat, syms.noSymbol, ! ((MethodSymbol)bsm).asHandle(), indyType, ! List.nil().toArray(new LoadableConstant[0])); Items.Item item = gen.getItems().makeDynamicItem(dynSym); item.invoke(); } finally { make.at(prevPos); --- 377,390 ---- bsm_staticArgs, null); Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcat, syms.noSymbol, ! ClassFile.REF_invokeStatic, ! (Symbol.MethodSymbol)bsm, indyType, ! List.nil().toArray()); Items.Item item = gen.getItems().makeDynamicItem(dynSym); item.invoke(); } finally { make.at(prevPos);
*** 415,425 **** for (List<JCTree> t : split) { Assert.check(!t.isEmpty(), "Arguments list is empty"); StringBuilder recipe = new StringBuilder(t.size()); ListBuffer<Type> dynamicArgs = new ListBuffer<>(); ! ListBuffer<LoadableConstant> staticArgs = new ListBuffer<>(); for (JCTree arg : t) { Object constVal = arg.type.constValue(); if ("".equals(constVal)) continue; if (arg.type == syms.botType) { --- 415,425 ---- for (List<JCTree> t : split) { Assert.check(!t.isEmpty(), "Arguments list is empty"); StringBuilder recipe = new StringBuilder(t.size()); ListBuffer<Type> dynamicArgs = new ListBuffer<>(); ! ListBuffer<Object> staticArgs = new ListBuffer<>(); for (JCTree arg : t) { Object constVal = arg.type.constValue(); if ("".equals(constVal)) continue; if (arg.type == syms.botType) {
*** 427,440 **** recipe.append((String) null); } else if (constVal != null) { // Concat the String representation of the constant, except // for the case it contains special tags, which requires us // to expose it as detached constant. ! String a = arg.type.stringValue(); if (a.indexOf(TAG_CONST) != -1 || a.indexOf(TAG_ARG) != -1) { recipe.append(TAG_CONST); ! staticArgs.add(LoadableConstant.String(a)); } else { recipe.append(a); } } else { // Ordinary arguments come through the dynamic arguments. --- 427,440 ---- recipe.append((String) null); } else if (constVal != null) { // Concat the String representation of the constant, except // for the case it contains special tags, which requires us // to expose it as detached constant. ! String a = ConstFold.stringValue(arg.type.getTag(), arg.type.constValue()); if (a.indexOf(TAG_CONST) != -1 || a.indexOf(TAG_ARG) != -1) { recipe.append(TAG_CONST); ! staticArgs.add(a); } else { recipe.append(a); } } else { // Ordinary arguments come through the dynamic arguments.
*** 462,489 **** doCall(type, pos, recipe.toString(), List.nil(), argTypes.toList()); } } /** Produce the actual invokedynamic call to StringConcatFactory */ ! private void doCall(Type type, JCDiagnostic.DiagnosticPosition pos, String recipe, List<LoadableConstant> staticArgs, List<Type> dynamicArgTypes) { Type.MethodType indyType = new Type.MethodType(dynamicArgTypes, type, List.nil(), syms.methodClass); int prevPos = make.pos; try { make.at(pos); ListBuffer<Type> constTypes = new ListBuffer<>(); ! ListBuffer<LoadableConstant> constants = new ListBuffer<>(); ! for (LoadableConstant t : staticArgs) { constants.add(t); constTypes.add(syms.stringType); } ! List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType, syms.stringType, syms.methodTypeType) .append(syms.stringType) .appendList(constTypes); --- 462,489 ---- doCall(type, pos, recipe.toString(), List.nil(), argTypes.toList()); } } /** Produce the actual invokedynamic call to StringConcatFactory */ ! private void doCall(Type type, JCDiagnostic.DiagnosticPosition pos, String recipe, List<Object> staticArgs, List<Type> dynamicArgTypes) { Type.MethodType indyType = new Type.MethodType(dynamicArgTypes, type, List.nil(), syms.methodClass); int prevPos = make.pos; try { make.at(pos); ListBuffer<Type> constTypes = new ListBuffer<>(); ! ListBuffer<Object> constants = new ListBuffer<>(); ! for (Object t : staticArgs) { constants.add(t); constTypes.add(syms.stringType); } ! List<Type> bsm_staticArgs = List.of(syms.methodHandlesLookupType, syms.stringType, syms.methodTypeType) .append(syms.stringType) .appendList(constTypes);
*** 494,507 **** bsm_staticArgs, null); Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcatWithConstants, syms.noSymbol, ! ((MethodSymbol)bsm).asHandle(), indyType, ! List.of(LoadableConstant.String(recipe)) ! .appendList(constants).toArray(new LoadableConstant[constants.size()])); Items.Item item = gen.getItems().makeDynamicItem(dynSym); item.invoke(); } finally { make.at(prevPos); --- 494,507 ---- bsm_staticArgs, null); Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcatWithConstants, syms.noSymbol, ! ClassFile.REF_invokeStatic, ! (Symbol.MethodSymbol)bsm, indyType, ! List.<Object>of(recipe).appendList(constants).toArray()); Items.Item item = gen.getItems().makeDynamicItem(dynSym); item.invoke(); } finally { make.at(prevPos);
< prev index next >