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.
20 import java.io.InputStream;
21 import java.io.PrintStream;
22 import java.nio.channels.Channel;
24 import java.util.Properties;
26 import sun.misc.JavaLangAccess;
27 import sun.misc.SharedSecrets;
28 import sun.nio.ch.Interruptible;
29 import sun.reflect.ConstantPool;
30 import sun.reflect.annotation.AnnotationType;
35 static Properties properties;
37 public static InputStream in; // new BufferedInputStream(...); // <2do> not yet
38 public static PrintStream out;
39 public static PrintStream err;
43 out = createSystemOut();
44 err = createSystemErr();
46 properties = new Properties();
48 String[] kv = getKeyValuePairs();
49 for (int i=0; i<kv.length; i+=2){
53 if (key != null && val != null) {
54 properties.put(kv[i], kv[i+1]);
58 // this is the Java 6 sun.misc.SharedSecrets backdoor mechanism which I
59 // would have prefered not to learn about. It's a mess WRT Java 1.5 / 6 compatibility
60 // <2do> - most if this isn't supported yet
61 SharedSecrets.setJavaLangAccess( createJavaLangAccess());
63 // <2do> this is an approximation that isn't particularly safe since we don't
64 // initialize sun.misc.VM
65 //sun.misc.VM.booted();
68 static JavaLangAccess createJavaLangAccess () {
69 return new JavaLangAccess(){
71 public ConstantPool getConstantPool(Class<?> cls) {
72 throw new UnsupportedOperationException("JavaLangAccess.getConstantPool() not supported yet");
73 //return cls.getConstantPool();
76 public void setAnnotationType(Class<?> cls, AnnotationType type) {
77 throw new UnsupportedOperationException("JavaLangAccess.setAnnotationType() not supported yet");
78 //cls.setAnnotationType(type);
81 public AnnotationType getAnnotationType(Class<?> cls) {
82 throw new UnsupportedOperationException("JavaLangAccess.getAnnotationType() not supported yet");
83 //return cls.getAnnotationType();
86 public <E extends Enum<E>> E[] getEnumConstantsShared(Class<E> cls) {
87 return cls.getEnumConstantsShared();
90 public void blockedOn(Thread t, Interruptible b) {
91 throw new UnsupportedOperationException("JavaLangAccess.blockedOn() not supported yet");
95 public void registerShutdownHook(int slot, Runnable r) {
96 throw new UnsupportedOperationException("JavaLangAccess.registerShutdownHook() not supported yet");
99 public int getStackTraceDepth(Throwable t) {
100 return t.getStackTraceDepth();
103 public StackTraceElement getStackTraceElement(Throwable t, int i) {
104 StackTraceElement[] st = t.getStackTrace();
110 static private native String[] getKeyValuePairs();
112 static private native PrintStream createSystemOut();
113 static private native PrintStream createSystemErr();
115 //--- standard streams
116 public static void setIn (InputStream newIn) {
120 public static void setOut (PrintStream newOut){
124 public static void setErr (PrintStream newErr) {
128 public static Channel inheritedChannel() {
129 throw new UnsupportedOperationException("inheritedChannel() not yet supported");
133 public static native void exit (int rc);
134 public static native void arraycopy (Object src, int srcPos,
135 Object dst, int dstPos, int len);
136 public static native void gc();
137 public static native void runFinalization();
138 public static native void runFinalizersOnExit(boolean cond);
139 static native Class<?> getCallerClass();
140 public static native int identityHashCode (Object o);
143 //--- time management
144 public static native long currentTimeMillis();
145 public static native long nanoTime();
148 public static native String getenv (String key);
149 public static Map<String,String> getenv() {
150 throw new UnsupportedOperationException("getenv() not yet supported");
153 //--- security manager
154 static SecurityManager securityManager;
156 public static void setSecurityManager (SecurityManager newManager) {
157 securityManager = newManager;
160 public static SecurityManager getSecurityManager() {
161 return securityManager;
164 //--- system properties
166 public static Properties getProperties() {
169 public static void setProperties(Properties newProps){
170 properties = newProps;
173 public static String getProperty (String key) {
174 return properties.getProperty(key);
177 public static String getProperty (String key, String def){
178 String v = properties.getProperty(key);
186 public static String setProperty (String key, String value){
187 String oldVal = properties.getProperty(key);
188 properties.put(key,value);
192 public static String clearProperty (String key) {
193 String oldVal = properties.getProperty(key);
194 properties.remove(key);
199 public static void load (String pathName) {
200 // nothing, we don't have native libs
201 // (maybe we could on-demand load peers?)
204 public static void loadLibrary (String libName){
208 public static String mapLibraryName (String libName){
209 // just a placeholder (Unix flavor)
210 return "lib" + libName + ".so";