changeset 17:e15b03204dc7

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
author Peter Mehlitz <pcmehlitz@gmail.com>
date Mon, 23 Mar 2015 12:54:20 -0700
parents 08ca336d5928
children a9ada67f1799
files .idea/uiDesigner.xml src/annotations/gov/nasa/jpf/annotation/NoJPFExecution.java src/main/gov/nasa/jpf/vm/ClassInfo.java src/main/gov/nasa/jpf/vm/MethodInfo.java src/main/gov/nasa/jpf/vm/NativeMethodInfo.java src/main/gov/nasa/jpf/vm/NoJPFExec.java src/main/gov/nasa/jpf/vm/ThreadInfo.java src/tests/gov/nasa/jpf/test/mc/basic/JPF_gov_nasa_jpf_test_mc_basic_NoJPFExecTest.java src/tests/gov/nasa/jpf/test/mc/basic/NoJPFExecTest.java
diffstat 9 files changed, 316 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>
\ No newline at end of file
--- /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 {
+}
--- 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<ClassInfo> set, String[] interfaces) throws ClassInfoException {
     if (interfaces != null) {
--- 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);
--- 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;
   }
--- /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();
+}
--- 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);
--- /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");
+  }
+}
--- /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();
+    }
+  }
+
+}