Preparing for tracking the object creation etc.
[jpf-core.git] / src / peers / gov / nasa / jpf / vm / JPF_java_util_concurrent_atomic_AtomicInteger.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;
20
21 import gov.nasa.jpf.annotation.MJI;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.NativePeer;
24
25 /**
26 * native peer for java.util.concurrent.atomic.AtomicInteger
27 * this implementation just cuts off native methods
28 */
29 public class JPF_java_util_concurrent_atomic_AtomicInteger extends NativePeer {
30
31   @MJI
32   public void $clinit____V (MJIEnv env, int rcls) {
33     // don't let this one pass, it calls native methods from non-public Sun classes
34   }
35  
36   @MJI
37   public boolean compareAndSet__II__Z (MJIEnv env, int objRef, int expect, int update){
38     int value = env.getIntField(objRef, "value");
39     if (value == expect){
40       env.setIntField(objRef, "value", update);
41       return true;
42     } else {
43       return false;
44     }
45   }
46   
47   @MJI
48   public int getAndAdd__I__I (MJIEnv env, int objRef, int delta) {
49     int value = env.getIntField(objRef, "value");
50     env.setIntField(objRef, "value", value + delta);
51     return value;
52   }
53   
54   @MJI
55   public int getAndIncrement____I (MJIEnv env, int objRef) {
56     int value = env.getIntField(objRef, "value");
57     env.setIntField(objRef, "value", value + 1);
58     return value;
59   }
60   
61   @MJI
62   public int getAndDecrement____I (MJIEnv env, int objRef) {
63     int value = env.getIntField(objRef, "value");
64     env.setIntField(objRef, "value", value - 1);
65     return value;
66   }
67   
68   @MJI
69   public void lazySet__I__V (MJIEnv env, int objRef, int newValue) {
70     env.setIntField(objRef, "value", newValue);
71   }
72
73   @MJI
74   public int getAndSet__I__I (MJIEnv env, int objRef, int newValue) {
75     int value = env.getIntField(objRef, "value");
76     env.setIntField(objRef, "value", newValue);
77     return value;
78   }
79
80   @MJI
81   public boolean weakCompareAndSet__II__Z (MJIEnv env, int objRef, int expect, int update) {
82     int value = env.getIntField(objRef, "value");
83     if (value == expect){
84       env.setIntField(objRef, "value", update);
85       return true;
86     } else {
87       return false;
88     }
89   }
90   
91   @MJI
92   public int incrementAndGet____I (MJIEnv env, int objRef) {
93     int value = env.getIntField(objRef, "value");
94     value++;
95     env.setIntField(objRef, "value", value);
96     return value;
97   }
98   
99   @MJI
100   public int decrementAndGet____I (MJIEnv env, int objRef) {
101     int value = env.getIntField(objRef, "value");
102     value--;
103     env.setIntField(objRef, "value", value);
104     return value;
105   }
106   
107   @MJI
108   public int addAndGet__I__I (MJIEnv env, int objRef, int delta) {
109     int value = env.getIntField(objRef, "value");
110     value += delta;
111     env.setIntField(objRef, "value", value);
112     return value;
113   }
114 }