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.annotation.MJI;
24 * peer for java.lang.ThreadLocal
26 public class JPF_java_lang_ThreadLocal extends NativePeer {
29 public int getEntry____Ljava_lang_ThreadLocal$Entry_2 (MJIEnv env, int objRef){
30 ThreadInfo ti = env.getThreadInfo();
31 int tObjRef = ti.getThreadObjectRef();
33 int aRef = env.getReferenceField(tObjRef, "threadLocals");
34 if (aRef == MJIEnv.NULL){
37 int[] erefs = env.getReferenceArrayObject(aRef);
38 int len = env.getArrayLength(aRef);
41 for (int i=0; i<len; i++){
43 int k = env.getReferenceField(e, "ref");
54 public void addEntry__Ljava_lang_ThreadLocal$Entry_2 (MJIEnv env, int objRef, int eRef){
55 ThreadInfo ti = env.getThreadInfo();
56 int tObjRef = ti.getThreadObjectRef();
57 int aRef = env.getReferenceField(tObjRef, "threadLocals");
59 if (aRef == MJIEnv.NULL){ // first entry
60 int newaRef = env.newObjectArray("Ljava/lang/ThreadLocal.Entry;", 1);
61 env.setReferenceArrayElement(newaRef, 0, eRef);
62 env.setReferenceField(tObjRef, "threadLocals", newaRef);
65 int len = env.getArrayLength(aRef);
66 int[] erefs = env.getReferenceArrayObject(aRef);
69 int newaRef = env.newObjectArray("Ljava/lang/ThreadLocal.Entry;", len+1);
70 env.arrayCopy(aRef, 0, newaRef, 0, len);
71 env.setReferenceArrayElement(newaRef, len, eRef);
72 env.setReferenceField(tObjRef, "threadLocals", newaRef);
78 public void removeEntry__Ljava_lang_ThreadLocal$Entry_2 (MJIEnv env, int objRef, int eRef){
79 ThreadInfo ti = env.getThreadInfo();
80 int tObjRef = ti.getThreadObjectRef();
81 int aRef = env.getReferenceField(tObjRef, "threadLocals");
83 if (aRef != MJIEnv.NULL){
84 int len = env.getArrayLength(aRef);
85 int[] erefs = env.getReferenceArrayObject(aRef);
86 int newaRef = env.newObjectArray("Ljava/lang/ThreadLocal.Entry;", len-1);
88 for (int i=0, j=0; i<len; i++){
91 env.setReferenceArrayElement(newaRef, j++, e);
95 env.setReferenceField(tObjRef, "threadLocals", newaRef);