merge from gnuclasspath branch. I hope I didn't miss or revert any modifications...
[cacao.git] / src / native / vm / VMRuntime.c
1 /* class: java/lang/Runtime */
2
3
4 #define JOWENN_DEBUG
5
6 /*
7  * Class:     java_lang_Runtime
8  * Method:    execInternal
9  * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;
10  */
11 JNIEXPORT struct java_lang_Process* JNICALL Java_java_lang_Runtime_execInternal (JNIEnv *env ,  struct java_lang_Runtime* this ,
12         java_objectarray* cmd, java_objectarray* shellenv, struct java_io_File* workingdir)
13 {
14   log_text("Java_java_lang_Runtime_execInternal  called");
15   return NULL;
16 }
17 /*
18  * Class:     java/lang/Runtime
19  * Method:    exitInternal
20  * Signature: (I)V
21  */
22 JNIEXPORT void JNICALL Java_java_lang_Runtime_exitInternal ( JNIEnv *env ,  struct java_lang_Runtime* this, s4 par1)
23 {
24         cacao_shutdown (par1);
25 }
26 /*
27  * Class:     java/lang/Runtime
28  * Method:    freeMemory
29  * Signature: ()J
30  */
31 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_freeMemory ( JNIEnv *env ,  struct java_lang_Runtime* this)
32 {
33         log_text ("java_lang_Runtime_freeMemory called");
34         return builtin_i2l (0);
35 }
36 /*
37  * Class:     java/lang/Runtime
38  * Method:    gc
39  * Signature: ()V
40  */
41 JNIEXPORT void JNICALL Java_java_lang_Runtime_gc ( JNIEnv *env ,  struct java_lang_Runtime* this)
42 {
43         gc_call();
44 }
45 /*
46  * Class:     java/lang/Runtime
47  * Method:    runFinalization
48  * Signature: ()V
49  */
50 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalization ( JNIEnv *env, struct java_lang_Runtime* this)
51 {
52   log_text("Java_java_lang_Runtime_runFinalization0  called");
53 }
54 /*
55  * Class:     java/lang/Runtime
56  * Method:    runFinalizersOnExit
57  * Signature: (Z)V
58  */
59 JNIEXPORT void JNICALL Java_java_lang_Runtime_runFinalizersOnExitInternal ( JNIEnv *env ,  jclass clazz, s4 par1)
60 {
61   log_text("Java_java_lang_Runtime_runFinalizersOnExit0  called");
62 }
63 /*
64  * Class:     java/lang/Runtime
65  * Method:    totalMemory
66  * Signature: ()J
67  */
68 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_totalMemory ( JNIEnv *env ,  struct java_lang_Runtime* this)
69 {
70         log_text ("java_lang_Runtime_totalMemory called");
71         return builtin_i2l (0);
72 }
73 /*
74  * Class:     java/lang/Runtime
75  * Method:    traceInstructions
76  * Signature: (Z)V
77  */
78 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceInstructions ( JNIEnv *env ,  struct java_lang_Runtime* this, s4 par1)
79 {
80   log_text("Java_java_lang_Runtime_traceInstructions  called");
81 }
82 /*
83  * Class:     java/lang/Runtime
84  * Method:    traceMethodCalls
85  * Signature: (Z)V
86  */
87 JNIEXPORT void JNICALL Java_java_lang_Runtime_traceMethodCalls ( JNIEnv *env ,  struct java_lang_Runtime* this, s4 par1)
88 {
89   log_text("Java_java_lang_Runtime_traceMethodCalls  called");
90 }
91
92
93 /*
94  * Class:     java_lang_Runtime
95  * Method:    availableProcessors
96  * Signature: ()I
97  */
98 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_availableProcessors (JNIEnv *env ,  struct java_lang_Runtime* this ) {
99         log_text("Java_java_lang_Runtime_availableProcessors called, returning hardcoded 1");
100         return 1;
101 }
102
103
104
105 /*
106  * Class:     java_lang_Runtime
107  * Method:    nativeLoad
108  * Signature: (Ljava/lang/String;)I
109  */
110 JNIEXPORT s4 JNICALL Java_java_lang_Runtime_nativeLoad (JNIEnv *env ,  struct java_lang_Runtime* this , struct java_lang_String* 
111 par1) {
112 #ifdef JOWENN_DEBUG     
113         char *buffer;                   
114         int buffer_len, pos;
115         utf * data;
116         
117         data=javastring_toutf(par1,0);
118         
119         if (!data) {
120                 log_text("nativeLoad: Error: empty string");
121                 return 1;
122         }
123         
124         buffer_len = 
125           utf_strlen(data)+ 40;
126
127                 
128         buffer = MNEW(char, buffer_len);
129
130         strcpy(buffer, "Java_java_lang_Runtime_nativeLoad:");
131         utf_sprint(buffer+strlen(data), data);
132         log_text(buffer);       
133
134         MFREE(buffer, char, buffer_len);
135 #endif
136         log_text("Java_java_lang_Runtime_nativeLoad");
137         return 1;
138 }
139
140 /*
141  * Class:     java_lang_Runtime
142  * Method:    nativeGetLibname
143  * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
144  */
145 JNIEXPORT struct java_lang_String* JNICALL Java_java_lang_Runtime_nativeGetLibname (JNIEnv *env , jclass clazz, struct java_lang_String* par1,
146 struct java_lang_String* par2) {
147 #ifdef JOWENN_DEBUG     
148         char *buffer;                   
149         int buffer_len, pos;
150         utf * data;
151         int i;
152         
153         java_lang_String *str = (java_lang_String *) par1;;     
154         
155         data=javastring_toutf(par2,0);
156         
157                 if (!data) {
158                 log_text("nativeGetLibName: Error: empty string");
159                 return 0;;
160         }
161         
162         buffer_len = 
163           utf_strlen(data)+ 40;
164         
165         buffer = MNEW(char, buffer_len);
166
167         strcpy(buffer, "Java_java_lang_Runtime_nativeGetLibname:");
168         utf_sprint(buffer+strlen(data), data);
169         log_text(buffer);       
170
171         MFREE(buffer, char, buffer_len);
172 #endif
173         log_text("Java_java_lang_Runtime_nativeGetLibname");
174         return 0;
175 }
176
177
178 #define MAXPROPS 100
179 static int activeprops = 19;  
180    
181 static char *proplist[MAXPROPS][2] = {
182         { "java.class.path", NULL },
183         { "java.home", NULL },
184         { "user.home", NULL },  
185         { "user.name", NULL },
186         { "user.dir",  NULL },
187                                 
188         { "os.arch", NULL },
189         { "os.name", NULL },
190         { "os.version", NULL },
191                                          
192         { "java.class.version", "45.3" },
193         { "java.version", PACKAGE":"VERSION },
194         { "java.vendor", "CACAO Team" },
195         { "java.vendor.url", "http://www.complang.tuwien.ac.at/java/cacao/" },
196         { "java.vm.name","CACAO"}, 
197         { "java.tmpdir","/tmp/"},
198         { "java.io.tmpdir","/tmp/"},
199
200         { "path.separator", ":" },
201         { "file.separator", "/" },
202         { "line.separator", "\n" },
203         { "java.protocol.handler.pkgs","gnu.java.net.protocol"}
204 };
205
206
207 /*
208  * Class:     java_lang_Runtime
209  * Method:    insertSystemProperties
210  * Signature: (Ljava/util/Properties;)V
211  */
212 JNIEXPORT void JNICALL Java_java_lang_Runtime_insertSystemProperties (JNIEnv *env , jclass clazz, struct java_util_Properties* p) {
213
214         #define BUFFERSIZE 200
215         u4 i;
216         methodinfo *m;
217         char buffer[BUFFERSIZE];
218         java_objectheader *o;
219         struct utsname utsnamebuf;
220
221         log_text("Java_java_lang_Runtime_insertSystemProperties");
222
223         proplist[0][1] = classpath;
224         proplist[1][1] = getenv("JAVA_HOME");
225         proplist[2][1] = getenv("HOME");
226         proplist[3][1] = getenv("USER");
227         proplist[4][1] = getcwd(buffer,BUFFERSIZE);
228
229         /* get properties from system */
230         uname(&utsnamebuf);
231         proplist[5][1] = utsnamebuf.machine;
232         proplist[6][1] = utsnamebuf.sysname;
233         proplist[7][1] = utsnamebuf.release;
234
235         if (!p) panic ("Java_java_lang_Runtime_insertSystemProperties called with  NULL-Argument");
236
237         /* search for method to add properties */
238         m = class_resolvemethod (
239                 p->header.vftbl->class,
240                 utf_new_char ("put"),
241                 utf_new_char ("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")
242         );
243
244         if (!m) panic ("Can not find method 'put' for class Properties");
245
246         /* add the properties */
247         for (i=0; i<activeprops; i++) {
248
249             if (proplist[i][1]==NULL) proplist[i][1]="";
250
251             asm_calljavamethod(m,  p,
252                                 javastring_new_char(proplist[i][0]),
253                                 javastring_new_char(proplist[i][1]),
254                                         NULL
255                                 );
256         }
257
258         return p;
259
260 }
261
262
263 /*
264  * Class:     java_lang_Runtime
265  * Method:    maxMemory
266  * Signature: ()J
267  */
268 JNIEXPORT s8 JNICALL Java_java_lang_Runtime_maxMemory (JNIEnv *env ,  struct java_lang_Runtime* this ) {
269         log_text("Java_java_lang_Runtime_maxMemory");
270         return 0;
271 }
272