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;
21 import gov.nasa.jpf.vm.ClassInfo;
22 import gov.nasa.jpf.vm.ClassLoaderInfo;
23 import gov.nasa.jpf.vm.ElementInfo;
24 import gov.nasa.jpf.vm.Instruction;
25 import gov.nasa.jpf.vm.LoadOnJPFRequired;
26 import gov.nasa.jpf.vm.MethodInfo;
27 import gov.nasa.jpf.vm.StaticElementInfo;
28 import gov.nasa.jpf.vm.ThreadInfo;
29 import gov.nasa.jpf.vm.Types;
33 * Invoke a class (static) method
34 * ..., [arg1, [arg2 ...]] => ...
36 public class INVOKESTATIC extends JVMInvokeInstruction {
39 protected INVOKESTATIC (String clsDescriptor, String methodName, String signature){
40 super(clsDescriptor, methodName, signature);
43 protected ClassInfo getClassInfo () {
45 ci = ClassLoaderInfo.getCurrentResolvedClassInfo(cname);
51 public int getByteCode () {
56 public String toPostExecString(){
57 StringBuilder sb = new StringBuilder();
58 sb.append(getMnemonic());
60 sb.append( invokedMethod.getFullName());
62 if (invokedMethod.isMJI()){
63 sb.append(" [native]");
70 public StaticElementInfo getStaticElementInfo (){
71 return getClassInfo().getStaticElementInfo();
74 public int getClassObjectRef(){
75 return getClassInfo().getStaticElementInfo().getClassObjectRef();
79 public Instruction execute (ThreadInfo ti) {
83 callee = getInvokedMethod(ti);
84 } catch (LoadOnJPFRequired lre) {
89 return ti.createAndThrowException("java.lang.NoSuchMethodException", cname + '.' + mname);
92 // this can be actually different than (can be a base)
93 ClassInfo ciCallee = callee.getClassInfo();
95 if (ciCallee.initializeClass(ti)) {
96 // do class initialization before continuing
97 // note - this returns the next insn in the topmost clinit that just got pushed
101 if (callee.isSynchronized()) {
102 ElementInfo ei = ciCallee.getClassObject();
103 ei = ti.getScheduler().updateObjectSharedness(ti, ei, null); // locks most likely belong to shared objects
105 if (reschedulesLockAcquisition(ti, ei)){
110 setupCallee( ti, callee); // this creates, initializes and pushes the callee StackFrame
112 return ti.getPC(); // we can't just return the first callee insn if a listener throws an exception
116 public MethodInfo getInvokedMethod(){
117 if (invokedMethod != null){
118 return invokedMethod;
120 // Hmm, this would be pre-exec, but if the current thread is not the one executing the insn
121 // this might result in false sharedness of the class object
122 return getInvokedMethod( ThreadInfo.getCurrentThread());
127 public MethodInfo getInvokedMethod (ThreadInfo ti){
128 if (invokedMethod == null) {
129 ClassInfo clsInfo = getClassInfo();
130 if (clsInfo != null){
131 MethodInfo callee = clsInfo.getMethod(mname, true);
133 ClassInfo ciCallee = callee.getClassInfo(); // might be a superclass of ci, i.e. not what is referenced in the insn
135 if (!ciCallee.isRegistered()){
136 // if it wasn't registered yet, classLoaded listeners didn't have a chance yet to modify it..
137 ciCallee.registerClass(ti);
138 // .. and might replace/remove MethodInfos
139 callee = clsInfo.getMethod(mname, true);
141 invokedMethod = callee;
145 return invokedMethod;
148 // can be different thatn the ci - method can be in a superclass
149 public ClassInfo getInvokedClassInfo(){
150 return getInvokedMethod().getClassInfo();
153 public String getInvokedClassName(){
154 return getInvokedClassInfo().getName();
158 public int getArgSize () {
160 argSize = Types.getArgumentsSize(signature);
168 public String toString() {
169 // methodInfo not set outside real call context (requires target object)
170 return "invokestatic " + cname + '.' + mname;
174 public Object getFieldValue (String id, ThreadInfo ti) {
175 return getClassInfo().getStaticFieldValueObject(id);
179 public void accept(JVMInstructionVisitor insVisitor) {
180 insVisitor.visit(this);
184 public Instruction typeSafeClone(MethodInfo mi) {
185 INVOKESTATIC clone = null;
188 clone = (INVOKESTATIC) super.clone();
190 // reset the method that this insn belongs to
193 clone.invokedMethod = null;
194 clone.lastObj = Integer.MIN_VALUE;
196 } catch (CloneNotSupportedException e) {