Mercurial > hg > truffle
diff graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2709:7b7dbe19fafb
Remove all unresolved cases from HotspotXirGenerator, use more explicit Deopt, Deopt to lastState instead of stateBefore
author | Gilles Duboscq <gilles.duboscq@oracle.com> |
---|---|
date | Thu, 19 May 2011 11:36:41 +0200 |
parents | ed36daed4c43 |
children | 0efd77a02ea9 |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Wed May 18 11:53:06 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Thu May 19 11:36:41 2011 +0200 @@ -348,7 +348,7 @@ // this is a load of class constant which might be unresolved RiType riType = (RiType) con; if (!riType.isResolved()) { - append(new Deoptimize(graph, frameState.create(bci()))); + append(new Deoptimize(graph)); frameState.push(CiKind.Object, append(Constant.forObject(null, graph))); } else { frameState.push(CiKind.Object, append(new Constant(riType.getEncoding(Representation.JavaClass), graph))); @@ -562,36 +562,37 @@ int cpi = stream().readCPI(); RiType type = constantPool().lookupType(cpi, CHECKCAST); boolean isInitialized = type.isResolved(); - Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState); - CheckCast c = new CheckCast(type, typeInstruction, frameState.apop(), graph); - frameState.apush(append(c)); + Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi); + Value object = frameState.apop(); + if (typeInstruction != null) { + frameState.apush(append(new CheckCast(type, typeInstruction, object, graph))); + } else { + frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); + } } private void genInstanceOf() { int cpi = stream().readCPI(); RiType type = constantPool().lookupType(cpi, INSTANCEOF); boolean isInitialized = type.isResolved(); - //System.out.println("instanceof : type.isResolved() = " + type.isResolved() + "; type.isInitialized() = " + type.isInitialized()); - Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi, frameState); - Instruction result; + Value typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi); Value object = frameState.apop(); if (typeInstruction != null) { - result = new InstanceOf(type, typeInstruction, object, graph); + frameState.ipush(append(new InstanceOf(type, typeInstruction, object, graph))); } else { - result = Constant.forInt(0, graph); + frameState.ipush(appendConstant(CiConstant.INT_0)); } - frameState.ipush(append(result)); } void genNewInstance(int cpi) { RiType type = constantPool().lookupType(cpi, NEW); - FrameState stateBefore = null; - if (!type.isResolved()) { - stateBefore = frameState.create(bci()); + if (type.isResolved()) { + NewInstance n = new NewInstance(type, cpi, constantPool(), graph); + frameState.apush(append(n)); + } else { + append(new Deoptimize(graph)); + frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); } - NewInstance n = new NewInstance(type, cpi, constantPool(), graph); - n.setStateBefore(stateBefore); - frameState.apush(append(n)); } private void genNewTypeArray(int typeCode) { @@ -603,51 +604,54 @@ private void genNewObjectArray(int cpi) { RiType type = constantPool().lookupType(cpi, ANEWARRAY); - FrameState stateBefore = null; - if (!type.isResolved()) { - stateBefore = frameState.create(bci()); + Value length = frameState.ipop(); + if (type.isResolved()) { + NewArray n = new NewObjectArray(type, length, graph); + frameState.apush(append(n)); + } else { + append(new Deoptimize(graph)); + frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); } - NewArray n = new NewObjectArray(type, frameState.ipop(), graph); - frameState.apush(append(n)); - n.setStateBefore(stateBefore); + } private void genNewMultiArray(int cpi) { RiType type = constantPool().lookupType(cpi, MULTIANEWARRAY); - FrameState stateBefore = null; - if (!type.isResolved()) { - stateBefore = frameState.create(bci()); - } int rank = stream().readUByte(bci() + 3); Value[] dims = new Value[rank]; for (int i = rank - 1; i >= 0; i--) { dims[i] = frameState.ipop(); } - NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph); - frameState.apush(append(n)); - n.setStateBefore(stateBefore); + if (type.isResolved()) { + NewArray n = new NewMultiArray(type, dims, cpi, constantPool(), graph); + frameState.apush(append(n)); + } else { + append(new Deoptimize(graph)); + frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); + } } private void genGetField(int cpi, RiField field) { - // Must copy the state here, because the field holder must still be on the stack. - FrameState stateBefore = null; - if (!field.isResolved()) { - stateBefore = frameState.create(bci()); + CiKind kind = field.kind(); + Value receiver = frameState.apop(); + if (field.isResolved()) { + LoadField load = new LoadField(receiver, field, graph); + appendOptimizedLoadField(kind, load); + } else { + append(new Deoptimize(graph)); + frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph))); } - LoadField load = new LoadField(frameState.apop(), field, stateBefore, graph); - appendOptimizedLoadField(field.kind(), load); } private void genPutField(int cpi, RiField field) { - // Must copy the state here, because the field holder must still be on the stack. - FrameState stateBefore = null; - if (!field.isResolved()) { - stateBefore = frameState.create(bci()); + Value value = frameState.pop(field.kind().stackKind()); + Value receiver = frameState.apop(); + if (field.isResolved()) { + StoreField store = new StoreField(receiver, field, value, graph); + appendOptimizedStoreField(store); + } else { + append(new Deoptimize(graph)); } - Value value = frameState.pop(field.kind().stackKind()); - StoreField store = new StoreField(frameState.apop(), field, value, graph); - appendOptimizedStoreField(store); - store.setStateBefore(stateBefore); } private void genGetStatic(int cpi, RiField field) { @@ -660,35 +664,35 @@ if (constantValue != null) { frameState.push(constantValue.kind.stackKind(), appendConstant(constantValue)); } else { - FrameState stateBefore = frameState.create(bci()); - Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); - if (container == null) { - container = Constant.forObject(null, graph); + Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi); + CiKind kind = field.kind(); + if (container != null) { + LoadField load = new LoadField(container, field, graph); + appendOptimizedLoadField(kind, load); + } else { + append(new Deoptimize(graph)); + frameState.push(kind.stackKind(), append(Constant.defaultForKind(kind, graph))); } - LoadField load = new LoadField(container, field, stateBefore, graph); - appendOptimizedLoadField(field.kind(), load); } } private void genPutStatic(int cpi, RiField field) { RiType holder = field.holder(); - FrameState stateBefore = frameState.create(bci()); - Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi, frameState); + Value container = genTypeOrDeopt(RiType.Representation.StaticFields, holder, field.isResolved(), cpi); Value value = frameState.pop(field.kind().stackKind()); if (container != null) { StoreField store = new StoreField(container, field, value, graph); appendOptimizedStoreField(store); - if (!field.isResolved()) { - store.setStateBefore(stateBefore); - } + } else { + append(new Deoptimize(graph)); } } - private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi, FrameStateAccess stateBefore) { + private Value genTypeOrDeopt(RiType.Representation representation, RiType holder, boolean initialized, int cpi) { if (initialized) { return appendConstant(holder.getEncoding(representation)); } else { - append(new Deoptimize(graph, stateBefore.duplicate(bci()))); + append(new Deoptimize(graph)); return null; } } @@ -710,7 +714,7 @@ // Re-use the same resolution code as for accessing a static field. Even though // the result of resolution is not used by the invocation (only the side effect // of initialization is required), it can be commoned with static field accesses. - genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi, frameState); + genTypeOrDeopt(RiType.Representation.StaticFields, holder, isInitialized, cpi); } Value[] args = frameState.popArguments(target.signature().argumentSlots(false)); appendInvoke(INVOKESTATIC, target, args, cpi, constantPool); @@ -944,8 +948,8 @@ append(new LookupSwitch(frameState.ipop(), list, keys, stateBefore, isSafepoint, graph)); } - private Value appendConstant(CiConstant type) { - return appendWithBCI(new Constant(type, graph), bci()); + private Value appendConstant(CiConstant constant) { + return appendWithBCI(new Constant(constant, graph), bci()); } private Value append(Instruction x) {