Initial import
[jpf-core.git] / src / tests / gov / nasa / jpf / vm / multiProcess / JPF_gov_nasa_jpf_vm_multiProcess_ThreadTest.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
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
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
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.
17  */
18
19 package gov.nasa.jpf.vm.multiProcess;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import gov.nasa.jpf.annotation.MJI;
25 import gov.nasa.jpf.vm.MJIEnv;
26 import gov.nasa.jpf.vm.NativePeer;
27 import gov.nasa.jpf.vm.ThreadInfo;
28
29 /**
30  * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
31  */
32 public class JPF_gov_nasa_jpf_vm_multiProcess_ThreadTest extends NativePeer {
33   private static List<Integer> prcIds = new ArrayList<Integer>();
34
35   protected static void resetPrcIds() {
36     prcIds.clear();
37   }
38
39   private static List<ThreadInfo> threads =  new ArrayList<ThreadInfo>();
40
41   protected static void resetThreads() {
42     threads.clear();
43   }
44
45   @MJI
46   public void keepThread__Ljava_lang_Thread_2I__V(MJIEnv env, int objRef, int thdRef, int prcId) {
47     ThreadInfo ti = env.getThreadInfoForObjRef(thdRef);
48     if(!prcIds.contains(prcId)) {
49       prcIds.add(prcId);
50       threads.add(ti);
51     }
52   }
53
54   protected static List<ThreadInfo> getThreads() {
55     return threads;
56   }
57
58   private static List<Integer> threadIds = new ArrayList<Integer>();
59
60   @MJI
61   public static void addToThreads__Ljava_lang_Thread_2__V (MJIEnv env, int objRef, int thdRef) {
62     ThreadInfo ti = env.getThreadInfoForObjRef(thdRef);
63
64     int id = ti.getId();
65     if(!threadIds.contains(id)) {
66       threadIds.add(id);
67     }
68   }
69
70   protected static List<Integer> getThreadIds() {
71     return threadIds;
72   }
73 }