# HG changeset patch # User Peter Mehlitz # Date 1427140460 25200 # Node ID e15b03204dc7684f037c87ab0f17b739856ef465 # Parent 08ca336d5928b2f1a742f1cfea9d62c9cb52575c added a @NoJPFExecution annotation, which sets a NoJPFExec system attr on marked methods during class load time, which gets checked by ThreadInfo.enter(). Useful to flag methods which have to be intercepted/cut off when executing classes under JPF that can also be used outside. Especially useful to avoid the recursive JPF problem that can be caused by tests (which mix classpath and native_classpath). This currently throws a JPFException, but we could also turn this into a AssertionError in the SUT so that we get the SUT stack trace diff -r 08ca336d5928 -r e15b03204dc7 .idea/uiDesigner.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/uiDesigner.xml Mon Mar 23 12:54:20 2015 -0700 @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 08ca336d5928 -r e15b03204dc7 src/annotations/gov/nasa/jpf/annotation/NoJPFExecution.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/annotations/gov/nasa/jpf/annotation/NoJPFExecution.java Mon Mar 23 12:54:20 2015 -0700 @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2015, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package gov.nasa.jpf.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * annotation used to specify that a method is only supposed to be + * executed when running outside JPF + * + * This is useful for model classes that have methods which are intercepted + * or cut off by native peers, and we want to ensure that we never execute + * these when running under JPF. The standard case for such assertions is + * if we refer to JPF itself, and we don't want to get recursive when already + * executing under JPF + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +public @interface NoJPFExecution { +} diff -r 08ca336d5928 -r e15b03204dc7 src/main/gov/nasa/jpf/vm/ClassInfo.java --- a/src/main/gov/nasa/jpf/vm/ClassInfo.java Fri Mar 20 15:47:10 2015 -0700 +++ b/src/main/gov/nasa/jpf/vm/ClassInfo.java Mon Mar 23 12:54:20 2015 -0700 @@ -363,7 +363,7 @@ instanceFields[iInstance++] = fi; } - processJPFAttrAnnotation(fi); + processJPFAnnotations(fi); } iFields = instanceFields; @@ -376,7 +376,7 @@ protected void setMethod (MethodInfo mi){ mi.linkToClass(this); methods.put( mi.getUniqueName(), mi); - processJPFAttrAnnotation(mi); + processJPFAnnotations(mi); } public void setMethods (MethodInfo[] newMethods) { @@ -416,7 +416,19 @@ } } - public AnnotationInfo getResolvedAnnotationInfo (String typeName){ + protected void processNoJPFExecutionAnnotation(InfoObject infoObj) { + AnnotationInfo ai = infoObj.getAnnotation("gov.nasa.jpf.annotation.NoJPFExecution"); + if (ai != null) { + infoObj.addAttr(NoJPFExec.SINGLETON); + } + } + + protected void processJPFAnnotations(InfoObject infoObj) { + processJPFAttrAnnotation(infoObj); + processNoJPFExecutionAnnotation(infoObj); + } + + public AnnotationInfo getResolvedAnnotationInfo (String typeName){ return classLoader.getResolvedAnnotationInfo( typeName); } @@ -542,7 +554,7 @@ setAssertionStatus(); processJPFConfigAnnotation(); - processJPFAttrAnnotation(this); + processJPFAnnotations(this); loadAnnotationListeners(); } @@ -1658,8 +1670,6 @@ /** * Loads the ClassInfo for named class. - * @param set a Set to which the interface names (String) are added - * @param ifcs class to find interfaceNames for. */ void loadInterfaceRec (Set set, String[] interfaces) throws ClassInfoException { if (interfaces != null) { diff -r 08ca336d5928 -r e15b03204dc7 src/main/gov/nasa/jpf/vm/MethodInfo.java --- a/src/main/gov/nasa/jpf/vm/MethodInfo.java Fri Mar 20 15:47:10 2015 -0700 +++ b/src/main/gov/nasa/jpf/vm/MethodInfo.java Mon Mar 23 12:54:20 2015 -0700 @@ -928,6 +928,11 @@ return ((modifiers & Modifier.NATIVE) != 0); } + // overridden by NativeMethodInfo + public boolean isJPFExecutable (){ + return !hasAttr(NoJPFExec.class); + } + public int getNumberOfArguments () { if (nArgs < 0) { nArgs = Types.getNumberOfArguments(signature); diff -r 08ca336d5928 -r e15b03204dc7 src/main/gov/nasa/jpf/vm/NativeMethodInfo.java --- a/src/main/gov/nasa/jpf/vm/NativeMethodInfo.java Fri Mar 20 15:47:10 2015 -0700 +++ b/src/main/gov/nasa/jpf/vm/NativeMethodInfo.java Mon Mar 23 12:54:20 2015 -0700 @@ -77,6 +77,11 @@ return false; } + @Override + public boolean isJPFExecutable(){ + return true; // that's our only purpose in life + } + public NativePeer getNativePeer() { return peer; } diff -r 08ca336d5928 -r e15b03204dc7 src/main/gov/nasa/jpf/vm/NoJPFExec.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/gov/nasa/jpf/vm/NoJPFExec.java Mon Mar 23 12:54:20 2015 -0700 @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package gov.nasa.jpf.vm; + +import gov.nasa.jpf.SystemAttribute; + +/** + * InfoObject attr that flags a certain construct (field, method, class) is not supposed + * to be used under JPF. Useful for model classes that have or use features which have to be + * cut off / abstracted by means of native peers, and we want to catch violations as + * early as possible + */ +public class NoJPFExec implements SystemAttribute { + + // we only need one + public static final NoJPFExec SINGLETON = new NoJPFExec(); +} diff -r 08ca336d5928 -r e15b03204dc7 src/main/gov/nasa/jpf/vm/ThreadInfo.java --- a/src/main/gov/nasa/jpf/vm/ThreadInfo.java Fri Mar 20 15:47:10 2015 -0700 +++ b/src/main/gov/nasa/jpf/vm/ThreadInfo.java Mon Mar 23 12:54:20 2015 -0700 @@ -2230,7 +2230,12 @@ */ public void enter (){ MethodInfo mi = top.getMethodInfo(); - + + if (!mi.isJPFExecutable()){ + //printStackTrace(); + throw new JPFException("method is not JPF executable: " + mi); + } + if (mi.isSynchronized()){ int oref = mi.isStatic() ? mi.getClassInfo().getClassObjectRef() : top.getThis(); ElementInfo ei = getModifiableElementInfo( oref); diff -r 08ca336d5928 -r e15b03204dc7 src/tests/gov/nasa/jpf/test/mc/basic/JPF_gov_nasa_jpf_test_mc_basic_NoJPFExecTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tests/gov/nasa/jpf/test/mc/basic/JPF_gov_nasa_jpf_test_mc_basic_NoJPFExecTest.java Mon Mar 23 12:54:20 2015 -0700 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package gov.nasa.jpf.test.mc.basic; + +import gov.nasa.jpf.annotation.MJI; +import gov.nasa.jpf.vm.MJIEnv; +import gov.nasa.jpf.vm.NativePeer; + +/** + * native peer for NoJPFExecTest + */ +public class JPF_gov_nasa_jpf_test_mc_basic_NoJPFExecTest extends NativePeer { + + @MJI + public void bar____V (MJIEnv env, int objRef){ + System.out.println("this is the bar____V() method intercepted by the native peer"); + } +} diff -r 08ca336d5928 -r e15b03204dc7 src/tests/gov/nasa/jpf/test/mc/basic/NoJPFExecTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tests/gov/nasa/jpf/test/mc/basic/NoJPFExecTest.java Mon Mar 23 12:54:20 2015 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015, United States Government, as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All rights reserved. + * + * The Java Pathfinder core (jpf-core) platform is licensed under the + * Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package gov.nasa.jpf.test.mc.basic; + +import gov.nasa.jpf.annotation.NoJPFExecution; +import gov.nasa.jpf.util.test.TestJPF; +import gov.nasa.jpf.util.TypeRef; +import org.junit.Test; + +/** + * test for NoJPFExecution annotations + */ +public class NoJPFExecTest extends TestJPF { + + @NoJPFExecution + protected void foo(){ + System.out.println("!! foo() should not be executed under JPF"); + } + + @Test + public void testNoJPFExec(){ + if (verifyJPFException( new TypeRef("gov.nasa.jpf.JPFException"))){ + foo(); + } + } + + + @NoJPFExecution + protected void bar(){ + System.out.println("!! bar() bytecode should not be executed under JPF"); + } + + @Test + public void testInterceptedNoJPFExec(){ + if (verifyNoPropertyViolation()){ + bar(); + } + } + +}