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.Instruction;
22 import gov.nasa.jpf.vm.MethodInfo;
25 * helper class to factor out common GET code
27 * <2do> This is going to be moved into a Java 8 interface with default methods
29 public class GetHelper {
32 * do a little bytecode pattern analysis on the fly, to find out if a
33 * GETFIELD or GETSTATIC is just part of a "..synchronized (obj) {..} .."
34 * pattern, which usually translates into the following pattern:
36 * getfield / getstatic
42 * If it does, there is no need to break the transition since the object
43 * reference is not used for anything that can cause violations between
44 * the get and the monitorenter.
46 * <2do> We might want to extend this in the future to also cover sync on
47 * local vars, like "Object o = myField; synchronized(o){..}..", but then
48 * the check becomes more expensive since we get interspersed aload/astore
49 * insns, and some of the locals could be used outside the sync block. Not
50 * sure if it buys much on the bottom line
52 * <2do> this relies on javac code patterns. The dup/astore could
53 * lead to subsequent use of the object reference w/o corresponding get/putfield
54 * insns (if it's not a volatile), but this access would be either a call
55 * or a get/putfield on a share object, i.e. would be checked separately
57 protected static boolean isMonitorEnterPrologue(MethodInfo mi, int insnIndex){
58 Instruction[] code = mi.getInstructions();
59 int off = insnIndex+1;
61 if (off < code.length-3) {
62 // we don't reach out further than 3 instructions
63 if (code[off] instanceof DUP) {
66 if (code[off] instanceof ASTORE) {
70 if (code[off] instanceof MONITORENTER) {
76 return false; // if in doubt, we assume it is not part of a monitorenter code pattern