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.ArrayIndexOutOfBoundsExecutiveException;
21 import gov.nasa.jpf.vm.ElementInfo;
22 import gov.nasa.jpf.vm.Instruction;
23 import gov.nasa.jpf.vm.MJIEnv;
24 import gov.nasa.jpf.vm.Scheduler;
25 import gov.nasa.jpf.vm.StackFrame;
26 import gov.nasa.jpf.vm.ThreadInfo;
30 * abstraction for all array load instructions
32 * ..., array, index => ..., value
34 public abstract class ArrayLoadInstruction extends JVMArrayElementInstruction implements JVMInstruction {
37 public Instruction execute (ThreadInfo ti) {
38 StackFrame frame = ti.getModifiableTopFrame();
41 arrayRef = frame.peek(1); // ..,arrayRef,idx
42 if (arrayRef == MJIEnv.NULL) {
43 return ti.createAndThrowException("java.lang.NullPointerException");
45 ElementInfo eiArray = ti.getElementInfo(arrayRef);
47 indexOperandAttr = peekIndexAttr(ti);
48 arrayOperandAttr = peekArrayAttr(ti);
50 Scheduler scheduler = ti.getScheduler();
51 if (scheduler.canHaveSharedArrayCG( ti, this, eiArray, index)){ // don't modify the frame before this
52 eiArray = scheduler.updateArraySharedness(ti, eiArray, index);
53 if (scheduler.setsSharedArrayCG( ti, this, eiArray, index)){
58 frame.pop(2); // now we can pop index and array reference
61 push(frame, eiArray, index);
63 Object elementAttr = eiArray.getElementAttr(index);
64 if (elementAttr != null) {
65 if (getElementSize() == 1) {
66 frame.setOperandAttr(elementAttr);
68 frame.setLongOperandAttr(elementAttr);
74 } catch (ArrayIndexOutOfBoundsExecutiveException ex) {
75 return ex.getInstruction();
79 protected boolean isReference () {
84 * only makes sense pre-exec
87 public int peekArrayRef (ThreadInfo ti){
88 return ti.getTopFrame().peek(1);
92 public Object peekArrayAttr (ThreadInfo ti){
93 return ti.getTopFrame().getOperandAttr(1);
96 // wouldn't really be required for loads, but this is a general
97 // ArrayInstruction API
99 public int peekIndex (ThreadInfo ti){
100 return ti.getTopFrame().peek();
104 public Object peekIndexAttr (ThreadInfo ti){
105 return ti.getTopFrame().getOperandAttr();
108 protected abstract void push (StackFrame frame, ElementInfo e, int index)
109 throws ArrayIndexOutOfBoundsExecutiveException;
113 public boolean isRead() {
118 public void accept(JVMInstructionVisitor insVisitor) {
119 insVisitor.visit(this);