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.
19 package gov.nasa.jpf.jvm.bytecode;
21 import gov.nasa.jpf.vm.ElementInfo;
22 import gov.nasa.jpf.vm.ThreadInfo;
23 import gov.nasa.jpf.vm.bytecode.ArrayElementInstruction;
26 * abstract class for operations that access elements of arrays
28 public abstract class JVMArrayElementInstruction extends ArrayElementInstruction {
30 protected int arrayRef;
31 protected int index; // the accessed element
33 // we cache these to avoid the need for executeInstruction() listening
34 // if attrs are processed in instructionExecuted()
35 protected Object arrayOperandAttr;
36 protected Object indexOperandAttr;
38 // we need this to be abstract because of the LongArrayStore insns
40 abstract public int peekIndex (ThreadInfo ti);
41 abstract public int peekArrayRef (ThreadInfo ti);
43 abstract public Object peekIndexAttr (ThreadInfo ti);
44 abstract public Object peekArrayAttr (ThreadInfo ti);
46 public boolean isReferenceArray() {
51 public ElementInfo getElementInfo (ThreadInfo ti){
53 return ti.getElementInfo(arrayRef);
55 int ref = peekArrayRef(ti);
56 return ti.getElementInfo(arrayRef);
61 * only makes sense from an executeInstruction() or instructionExecuted() listener,
62 * it is undefined outside of insn exec notifications
64 public int getArrayRef (ThreadInfo ti){
66 return peekArrayRef(ti);
72 public Object getArrayOperandAttr (ThreadInfo ti){
74 return peekArrayAttr(ti);
76 return arrayOperandAttr;
80 public Object getIndexOperandAttr (ThreadInfo ti){
82 return peekIndexAttr(ti);
84 return indexOperandAttr;
90 public ElementInfo peekArrayElementInfo (ThreadInfo ti){
91 int aref = getArrayRef(ti);
92 return ti.getElementInfo(aref);
95 public int getIndex (ThreadInfo ti){
96 if (!isCompleted(ti)){
104 * return size of array elements in stack words (long,double: 2, all other: 1)
105 * e.g. used to determine where the object reference is on the stack
107 * should probably be abstract, but there are lots of subclasses and only LongArrayLoad/Store insns have different size
109 protected int getElementSize () {
114 public abstract boolean isRead();