Initial import
[jpf-core.git] / src / peers / gov / nasa / jpf / vm / JPF_java_lang_Runtime.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 package gov.nasa.jpf.vm;
19
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.annotation.MJI;
22 import gov.nasa.jpf.vm.JPF_gov_nasa_jpf_vm_Verify;
23 import gov.nasa.jpf.vm.MJIEnv;
24 import gov.nasa.jpf.vm.NativePeer;
25
26 /**
27  * just a dummy for now, to avoid UnsatisfiedLinkErrors
28  */
29 public class JPF_java_lang_Runtime extends NativePeer {
30
31   @MJI
32   public void addShutdownHook__Ljava_lang_Thread_2__V (MJIEnv env, int objref, int threadRef) {
33     // ignored for now
34   }
35
36   @MJI
37   public long totalMemory____J (MJIEnv env, int objref) {
38     // not really sure what to return here, since in reality this
39     // value can be non-deterministic
40     return 50000000;
41   }
42
43   @MJI
44   public long maxMemory____J (MJIEnv env, int objref) {
45     // yet another cut
46     return 70000000;
47   }
48
49   @MJI
50   public long freeMemory____J (MJIEnv env, int objref) {
51     // we don't have an upper limit for our heap space, and we don't
52     // keep track how much is used, so we just return a dummy
53     
54     // we could loop over the areas calling getHeapSize() on
55     // ElementInfos, but since we don't have a max, what would
56     // that be good for?
57     
58     return 10000000;
59   }
60
61   @MJI
62   public void gc____V (MJIEnv env, int objref){
63     env.gc();
64   }
65   
66   @MJI
67   public int availableProcessors____I (MJIEnv env, int objref){
68     // this is what all these Runtime data acquisition APIs should look like
69     // - since the value is oing to be used by the application, there should
70     // be a way to vary it with a CG
71     
72     Config conf = env.getConfig();
73     int maxProcessors = conf.getInt("cg.max_processors", 1);
74     
75     if (maxProcessors == 1) {
76       return 1;
77     } else {
78       return JPF_gov_nasa_jpf_vm_Verify.getInt__II__I(env,-1, 1,maxProcessors);
79     }
80   }
81 }