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.vm;
21 import gov.nasa.jpf.util.UnsortedArrayIntSet;
24 * set that stores threads via (search global) thread ids. Used to detect shared objects/classes,
25 * created by configured SharedObjectPolicy factory
27 * Note - this class modified contents of instances, i.e. it does destructive updates
28 * and hence has state carry-over between paths
30 public class TidSet extends UnsortedArrayIntSet implements ThreadInfoSet, Memento<ThreadInfoSet> {
34 public TidSet (ThreadInfo ti){
43 public ThreadInfoSet add (ThreadInfo ti) {
49 public ThreadInfoSet remove (ThreadInfo ti) {
58 public boolean contains (ThreadInfo ti) {
59 return contains( ti.getId());
63 public boolean isShared (ThreadInfo ti, ElementInfo ei){
64 return hasMultipleLiveThreads();
68 public boolean hasMultipleLiveThreads(){
73 boolean alreadyHadOne = false;
74 ThreadList tl = vm.getThreadList();
76 for (int i=0; i<size; i++){
77 ThreadInfo ti = tl.getThreadInfoForId(elements[i]);
78 if (ti != null && !ti.isTerminated()){
91 public boolean hasMultipleRunnableThreads(){
96 boolean alreadyHadOne = false;
97 ThreadList tl = vm.getThreadList();
99 for (int i=0; i<size; i++){
100 ThreadInfo ti = tl.getThreadInfoForId(elements[i]);
101 if (ti != null && ti.isRunnable()){
105 alreadyHadOne = true;
114 public String toString() {
115 StringBuilder sb = new StringBuilder();
116 sb.append(getClass().getName());
118 for (int i = 0; i<size; i++) {
122 sb.append(elements[i]);
126 return sb.toString();
130 //--- state management (TidSet instance per default are their own mementos)
133 public Memento<ThreadInfoSet> getMemento(){
138 public ThreadInfoSet restore(ThreadInfoSet inSitu) {