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.util.InstructionState;
21 import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
22 import gov.nasa.jpf.vm.ClassInfo;
23 import gov.nasa.jpf.vm.ElementInfo;
24 import gov.nasa.jpf.vm.Instruction;
25 import gov.nasa.jpf.vm.MJIEnv;
26 import gov.nasa.jpf.vm.Scheduler;
27 import gov.nasa.jpf.vm.StackFrame;
28 import gov.nasa.jpf.vm.ThreadInfo;
32 * Store into reference array
33 * ..., arrayref, index, value => ...
35 public class AASTORE extends ArrayStoreInstruction {
40 public boolean isReferenceArray() {
45 protected void popValue(StackFrame frame){
50 protected void setField (ElementInfo ei, int index) throws ArrayIndexOutOfBoundsExecutiveException {
51 ei.checkArrayBounds(index);
52 ei.setReferenceElement(index, value);
56 * overridden because AASTORE can cause ArrayStoreExceptions and exposure CGs
59 public Instruction execute (ThreadInfo ti) {
60 StackFrame frame = ti.getModifiableTopFrame();
61 int refValue = frame.peek();
62 int idx = frame.peek(1);
63 int aref = frame.peek(2);
68 if (aref == MJIEnv.NULL) {
69 return ti.createAndThrowException("java.lang.NullPointerException");
72 ElementInfo eiArray = ti.getModifiableElementInfo(aref);
74 if (!ti.isFirstStepInsn()){ // we only need to check this once
75 Instruction xInsn = checkArrayStoreException(ti, frame, eiArray);
81 boolean checkExposure = false;
82 Scheduler scheduler = ti.getScheduler();
83 if (scheduler.canHaveSharedArrayCG(ti, this, eiArray, idx)){
85 eiArray = scheduler.updateArraySharedness(ti, eiArray, index);
86 if (scheduler.setsSharedArrayCG(ti, this, eiArray, idx)){
91 // check if this gets re-executed from an exposure CG
92 if (frame.getAndResetFrameAttr(InstructionState.class) == null){
94 Object attr = frame.getOperandAttr();
95 eiArray.checkArrayBounds(idx);
96 eiArray.setReferenceElement(idx, refValue);
97 eiArray.setElementAttrNoClone(idx, attr);
99 } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
100 return ex.getInstruction();
104 if (refValue != MJIEnv.NULL) {
105 ElementInfo eiExposed = ti.getElementInfo(refValue);
106 if (scheduler.setsSharedObjectExposureCG(ti, this, eiArray, null, eiArray)) {
107 frame.addFrameAttr( InstructionState.processed);
119 protected Instruction checkArrayStoreException(ThreadInfo ti, StackFrame frame, ElementInfo ei){
120 ClassInfo c = ei.getClassInfo();
121 int refVal = frame.peek();
123 if (refVal != MJIEnv.NULL) { // no checks for storing 'null'
124 ClassInfo elementCi = ti.getClassInfo(refVal);
125 ClassInfo arrayElementCi = c.getComponentClassInfo();
126 if (!elementCi.isInstanceOf(arrayElementCi)) {
127 String exception = "java.lang.ArrayStoreException";
128 String exceptionDescription = elementCi.getName();
129 return ti.createAndThrowException(exception, exceptionDescription);
138 public int getByteCode () {
143 public void accept(JVMInstructionVisitor insVisitor) {
144 insVisitor.visit(this);