Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Simplify code
  • Loading branch information
mcimadamore committed Oct 26, 2023
1 parent 23d4ef6 commit 59c0bfe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import java.util.function.ToIntFunction;

import static com.sun.tools.javac.code.TypeTag.BOT;
import static com.sun.tools.javac.code.TypeTag.DOUBLE;
import static com.sun.tools.javac.code.TypeTag.INT;
import static com.sun.tools.javac.code.TypeTag.LONG;
import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Class;
import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Double;
Expand Down Expand Up @@ -401,7 +403,8 @@ void postop() {
*/
public void emitLdc(LoadableConstant constant) {
int od = poolWriter.putConstant(constant);
if (LoadableConstant.isLongOrDouble(constant)) {
Type constantType = types.constantType(constant);
if (constantType.hasTag(LONG) || constantType.hasTag(DOUBLE)) {
emitop2(ldc2w, od, constant);
} else if (od <= 255) {
emitop1(ldc1, od, constant);
Expand Down Expand Up @@ -1063,16 +1066,14 @@ public void emitop2(int op, int od, PoolConstant data) {
Type t = types.erasure((Type)data);
state.push(t);
break; }
case ldc2:
case ldc2w:
state.push(types.constantType((LoadableConstant)data));
break;
case instanceof_:
state.pop(1);
state.push(syms.intType);
break;
case ldc2:
state.push(types.constantType((LoadableConstant)data));
break;
case jsr:
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@

package com.sun.tools.javac.jvm;

import com.sun.tools.javac.code.Symbol.DynamicVarSymbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTag;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.Types.UniqueType;
import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant.BasicConstant;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Pair;
Expand Down Expand Up @@ -120,18 +117,6 @@ public Object poolKey(Types types) {
return data;
}
}

static boolean isLongOrDouble(LoadableConstant constant) {
return switch (constant) {
case DynamicVarSymbol dynamicVar ->
dynamicVar.type.hasTag(TypeTag.LONG) ||
dynamicVar.type.hasTag(TypeTag.DOUBLE);
case BasicConstant bc ->
bc.tag == ClassFile.CONSTANT_Long ||
bc.tag == ClassFile.CONSTANT_Double;
default -> false;
};
}
}

/**
Expand Down

0 comments on commit 59c0bfe

Please sign in to comment.