< prev index next >

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

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 24,38 **** */ package com.sun.tools.javac.jvm; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Code.*; ! import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant; ! import com.sun.tools.javac.jvm.PoolConstant.LoadableConstant.BasicConstant; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.Assert; import static com.sun.tools.javac.jvm.ByteCodes.*; --- 24,38 ---- */ package com.sun.tools.javac.jvm; import com.sun.tools.javac.code.*; + import com.sun.tools.javac.code.Kinds.Kind; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.jvm.Code.*; ! import com.sun.tools.javac.jvm.Pool.DynamicVariable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.Assert; import static com.sun.tools.javac.jvm.ByteCodes.*;
*** 50,62 **** * This code and its internal interfaces are subject to change or * deletion without notice.</b> */ public class Items { ! /** The current constant pool writer. */ ! PoolWriter poolWriter; /** The current code buffer. */ Code code; --- 50,62 ---- * This code and its internal interfaces are subject to change or * deletion without notice.</b> */ public class Items { ! /** The current constant pool. */ ! Pool pool; /** The current code buffer. */ Code code;
*** 72,84 **** private final Item voidItem; private final Item thisItem; private final Item superItem; private final Item[] stackItem = new Item[TypeCodeCount]; ! public Items(PoolWriter poolWriter, Code code, Symtab syms, Types types) { this.code = code; ! this.poolWriter = poolWriter; this.types = types; voidItem = new Item(VOIDcode) { public String toString() { return "void"; } }; thisItem = new SelfItem(false); --- 72,84 ---- private final Item voidItem; private final Item thisItem; private final Item superItem; private final Item[] stackItem = new Item[TypeCodeCount]; ! public Items(Pool pool, Code code, Symtab syms, Types types) { this.code = code; ! this.pool = pool; this.types = types; voidItem = new Item(VOIDcode) { public String toString() { return "void"; } }; thisItem = new SelfItem(false);
*** 163,172 **** --- 163,179 ---- */ Item makeImmediateItem(Type type, Object value) { return new ImmediateItem(type, value); } + /** Make an item representing a condy. + * @param value The condy value. + */ + Item makeCondyItem(DynamicVariable value) { + return new CondyItem(value); + } + /** Make an item representing an assignment expression. * @param lhs The item representing the assignment's left hand side. */ Item makeAssignItem(Item lhs) { return new AssignItem(lhs);
*** 444,495 **** super(Code.typecode(member.erasure(types))); this.member = member; } Item load() { ! code.emitop2(getstatic, member, PoolWriter::putMember); return stackItem[typecode]; } void store() { ! code.emitop2(putstatic, member, PoolWriter::putMember); } Item invoke() { MethodType mtype = (MethodType)member.erasure(types); int rescode = Code.typecode(mtype.restype); ! code.emitInvokestatic(member, mtype); return stackItem[rescode]; } public String toString() { return "static(" + member + ")"; } } /** An item representing a dynamic call site. */ class DynamicItem extends StaticItem { DynamicItem(Symbol member) { super(member); } Item load() { ! Assert.check(member.kind == Kinds.Kind.VAR); Type type = member.erasure(types); int rescode = Code.typecode(type); ! code.emitLdc((DynamicVarSymbol)member); return stackItem[rescode]; } ! void store() { Assert.error("this method shouldn't be invoked"); } Item invoke() { ! Assert.check(member.kind == Kinds.Kind.MTH); MethodType mtype = (MethodType)member.erasure(types); int rescode = Code.typecode(mtype.restype); ! code.emitInvokedynamic((DynamicMethodSymbol)member, mtype); return stackItem[rescode]; } public String toString() { return "dynamic(" + member + ")"; --- 451,531 ---- super(Code.typecode(member.erasure(types))); this.member = member; } Item load() { ! code.emitop2(getstatic, pool.put(member)); return stackItem[typecode]; } void store() { ! code.emitop2(putstatic, pool.put(member)); } Item invoke() { MethodType mtype = (MethodType)member.erasure(types); int rescode = Code.typecode(mtype.restype); ! code.emitInvokestatic(pool.put(member), mtype); return stackItem[rescode]; } public String toString() { return "static(" + member + ")"; } } + /** An item representing a condy + */ + class CondyItem extends Item { + DynamicVariable value; + + CondyItem(DynamicVariable value) { + super(Code.typecode(value.type)); + this.value = value; + } + + @Override + public String toString() { + return "condy(" + value + ")"; + } + + @Override + Item load() { + int idx = pool.put(value); + if (typecode == LONGcode || typecode == DOUBLEcode) { + code.emitop2(ldc2w, idx); + } else { + code.emitLdc(idx); + } + return stackItem[typecode]; + } + } + /** An item representing a dynamic call site. */ class DynamicItem extends StaticItem { DynamicItem(Symbol member) { super(member); } Item load() { ! Assert.check(member.kind == Kind.VAR); Type type = member.erasure(types); int rescode = Code.typecode(type); ! code.emitLdc(pool.put(member)); return stackItem[rescode]; } ! void store() { ! assert false; ! } Item invoke() { ! Assert.check(member.kind == Kind.MTH); MethodType mtype = (MethodType)member.erasure(types); int rescode = Code.typecode(mtype.restype); ! code.emitInvokedynamic(pool.put(member), mtype); return stackItem[rescode]; } public String toString() { return "dynamic(" + member + ")";
*** 513,539 **** this.member = member; this.nonvirtual = nonvirtual; } Item load() { ! code.emitop2(getfield, member, PoolWriter::putMember); return stackItem[typecode]; } void store() { ! code.emitop2(putfield, member, PoolWriter::putMember); } Item invoke() { MethodType mtype = (MethodType)member.externalType(types); int rescode = Code.typecode(mtype.restype); if ((member.owner.flags() & Flags.INTERFACE) != 0 && !nonvirtual) { ! code.emitInvokeinterface(member, mtype); } else if (nonvirtual) { ! code.emitInvokespecial(member, mtype); } else { ! code.emitInvokevirtual(member, mtype); } return stackItem[rescode]; } void duplicate() { --- 549,575 ---- this.member = member; this.nonvirtual = nonvirtual; } Item load() { ! code.emitop2(getfield, pool.put(member)); return stackItem[typecode]; } void store() { ! code.emitop2(putfield, pool.put(member)); } Item invoke() { MethodType mtype = (MethodType)member.externalType(types); int rescode = Code.typecode(mtype.restype); if ((member.owner.flags() & Flags.INTERFACE) != 0 && !nonvirtual) { ! code.emitInvokeinterface(pool.put(member), mtype); } else if (nonvirtual) { ! code.emitInvokespecial(pool.put(member), mtype); } else { ! code.emitInvokevirtual(pool.put(member), mtype); } return stackItem[rescode]; } void duplicate() {
*** 561,640 **** */ class ImmediateItem extends Item { /** The literal's value. */ ! final LoadableConstant value; ImmediateItem(Type type, Object value) { super(Code.typecode(type)); ! switch (typecode) { ! case BYTEcode: ! case SHORTcode: ! case CHARcode: ! case INTcode: ! this.value = LoadableConstant.Int((int)value); ! break; ! case LONGcode: ! this.value = LoadableConstant.Long((long)value); ! break; ! case FLOATcode: ! this.value = LoadableConstant.Float((float)value); ! break; ! case DOUBLEcode: ! this.value = LoadableConstant.Double((double)value); ! break; ! case OBJECTcode: ! this.value = LoadableConstant.String((String)value); ! break; ! default: ! throw new UnsupportedOperationException("unsupported tag: " + typecode); ! } } private void ldc() { if (typecode == LONGcode || typecode == DOUBLEcode) { ! code.emitop2(ldc2w, value, PoolWriter::putConstant); } else { ! code.emitLdc(value); } } - private Number numericValue() { - return (Number)((BasicConstant)value).data; - } - Item load() { switch (typecode) { case INTcode: case BYTEcode: case SHORTcode: case CHARcode: ! int ival = numericValue().intValue(); if (-1 <= ival && ival <= 5) code.emitop0(iconst_0 + ival); else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE) code.emitop1(bipush, ival); else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE) code.emitop2(sipush, ival); else ldc(); break; case LONGcode: ! long lval = numericValue().longValue(); if (lval == 0 || lval == 1) code.emitop0(lconst_0 + (int)lval); else ldc(); break; case FLOATcode: ! float fval = numericValue().floatValue(); if (isPosZero(fval) || fval == 1.0 || fval == 2.0) code.emitop0(fconst_0 + (int)fval); else { ldc(); } break; case DOUBLEcode: ! double dval = numericValue().doubleValue(); if (isPosZero(dval) || dval == 1.0) code.emitop0(dconst_0 + (int)dval); else ldc(); break; --- 597,652 ---- */ class ImmediateItem extends Item { /** The literal's value. */ ! Object value; ImmediateItem(Type type, Object value) { super(Code.typecode(type)); ! this.value = value; } private void ldc() { + int idx = pool.put(value); if (typecode == LONGcode || typecode == DOUBLEcode) { ! code.emitop2(ldc2w, idx); } else { ! code.emitLdc(idx); } } Item load() { switch (typecode) { case INTcode: case BYTEcode: case SHORTcode: case CHARcode: ! int ival = ((Number)value).intValue(); if (-1 <= ival && ival <= 5) code.emitop0(iconst_0 + ival); else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE) code.emitop1(bipush, ival); else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE) code.emitop2(sipush, ival); else ldc(); break; case LONGcode: ! long lval = ((Number)value).longValue(); if (lval == 0 || lval == 1) code.emitop0(lconst_0 + (int)lval); else ldc(); break; case FLOATcode: ! float fval = ((Number)value).floatValue(); if (isPosZero(fval) || fval == 1.0 || fval == 2.0) code.emitop0(fconst_0 + (int)fval); else { ldc(); } break; case DOUBLEcode: ! double dval = ((Number)value).doubleValue(); if (isPosZero(dval) || dval == 1.0) code.emitop0(dconst_0 + (int)dval); else ldc(); break;
*** 657,667 **** private boolean isPosZero(double x) { return x == 0.0d && 1.0d / x > 0.0d; } CondItem mkCond() { ! int ival = numericValue().intValue(); return makeCondItem(ival != 0 ? goto_ : dontgoto); } Item coerce(int targetcode) { if (typecode == targetcode) { --- 669,679 ---- private boolean isPosZero(double x) { return x == 0.0d && 1.0d / x > 0.0d; } CondItem mkCond() { ! int ival = ((Number)value).intValue(); return makeCondItem(ival != 0 ? goto_ : dontgoto); } Item coerce(int targetcode) { if (typecode == targetcode) {
*** 672,706 **** if (Code.truncate(typecode) == INTcode) return this; else return new ImmediateItem( syms.intType, ! numericValue().intValue()); case LONGcode: return new ImmediateItem( syms.longType, ! numericValue().longValue()); case FLOATcode: return new ImmediateItem( syms.floatType, ! numericValue().floatValue()); case DOUBLEcode: return new ImmediateItem( syms.doubleType, ! numericValue().doubleValue()); case BYTEcode: return new ImmediateItem( syms.byteType, ! (int)(byte)numericValue().intValue()); case CHARcode: return new ImmediateItem( syms.charType, ! (int)(char)numericValue().intValue()); case SHORTcode: return new ImmediateItem( syms.shortType, ! (int)(short)numericValue().intValue()); default: return super.coerce(targetcode); } } } --- 684,718 ---- if (Code.truncate(typecode) == INTcode) return this; else return new ImmediateItem( syms.intType, ! ((Number)value).intValue()); case LONGcode: return new ImmediateItem( syms.longType, ! ((Number)value).longValue()); case FLOATcode: return new ImmediateItem( syms.floatType, ! ((Number)value).floatValue()); case DOUBLEcode: return new ImmediateItem( syms.doubleType, ! ((Number)value).doubleValue()); case BYTEcode: return new ImmediateItem( syms.byteType, ! (int)(byte)((Number)value).intValue()); case CHARcode: return new ImmediateItem( syms.charType, ! (int)(char)((Number)value).intValue()); case SHORTcode: return new ImmediateItem( syms.shortType, ! (int)(short)((Number)value).intValue()); default: return super.coerce(targetcode); } } }
< prev index next >