2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.jvm.bytecode;
20 import gov.nasa.jpf.vm.Instruction;
21 import gov.nasa.jpf.vm.ClassInfo;
22 import gov.nasa.jpf.vm.ElementInfo;
23 import gov.nasa.jpf.vm.LoadOnJPFRequired;
24 import gov.nasa.jpf.vm.StackFrame;
25 import gov.nasa.jpf.vm.ThreadInfo;
26 import gov.nasa.jpf.vm.Types;
30 * Push item from runtime constant pool
33 public class LDC extends Instruction implements JVMInstruction {
35 public enum Type {STRING, CLASS, INT, FLOAT};
39 protected String string; // the string value if Type.STRING, classname if Type.CLASS
44 public LDC (String s, boolean isClass){
46 string = Types.getClassNameFromTypeName(s);
60 value = Float.floatToIntBits(f);
66 public Instruction execute (ThreadInfo ti) {
67 StackFrame frame = ti.getModifiableTopFrame();
71 // too bad we can't cache it, since location might change between different paths
72 ElementInfo eiValue = ti.getHeap().newInternString(string, ti);
73 value = eiValue.getObjectRef();
84 // resolve the referenced class
86 ci = ti.resolveReferencedClass(string);
87 } catch(LoadOnJPFRequired lre) {
91 // LDC doesn't cause a <clinit> - we only register all required classes
92 // to make sure we have class objects. <clinit>s are called prior to
94 if (!ci.isRegistered()) {
98 frame.pushRef( ci.getClassObjectRef());
107 public int getLength() {
108 return 2; // opcode, index
112 public int getByteCode () {
116 public int getValue() {
120 public Type getType() {
124 public boolean isString() {
125 return (type == Type.STRING);
128 public float getFloatValue(){
129 if(type!=Type.FLOAT){
130 throw new IllegalStateException();
133 return Float.intBitsToFloat(value);
136 public String getStringValue() { // if it is a String (not acquired from the class const pool)
137 if (type == Type.STRING) {
144 public String getClassValue() { // if it is the name of a Class (acquired from the class const pool)
145 if (type == Type.CLASS) {
154 public void accept(JVMInstructionVisitor insVisitor) {
155 insVisitor.visit(this);