1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * This source file is part of SableVM. *
3 * *
4 * See the file "LICENSE" for the copyright information and for *
5 * the terms and conditions for copying, distribution and *
6 * modification of this source file. *
7 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8
9 /* m4svm_file_name */
10
11 /*
12 ----------------------------------------------------------------------
13 m4svm_NewArray
14 ----------------------------------------------------------------------
15 */
16
17 m4svm_define_begin v = ":], [:m4svm_NewArray:])";
18
19 /*
20 -----------------------------------m4_dnl
21 -----------------------------------
22 New$1Array
23 -----------------------------------m4_dnl
24 -----------------------------------
25 */
26
27 JNIEXPORT svm_static j$2Array JNICALL
New$1Array(JNIEnv * _env,jsize length)28 New$1Array (JNIEnv *_env, jsize length)
29 {
30 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
31 _svmt_JavaVM *vm = env->vm;
32
33 jarray array = NULL;
34
35 assert (env == _svmf_get_current_env ());
36
37 _svmm_resuming_java (env);
38
39 {
40 array = _svmf_get_jni_frame_native_local_array (env);
41 if (_svmm_new_array_instance
42 (env, vm->class_loading.boot_loader.classes.$2_array, length,
43 *array) != JNI_OK)
44 {
45 array = NULL;
46 goto end;
47 }
48
49 }
50
51 end:
52 _svmm_stopping_java (env);
53
54 return array;
55 }
56
57 m4svm_define_end v = ":])";
58
59 /* m4svm_NewArray(Boolean, boolean) */
60 /* m4svm_NewArray(Byte, byte) */
61 /* m4svm_NewArray(Short, short) */
62 /* m4svm_NewArray(Char, char) */
63 /* m4svm_NewArray(Int, int) */
64 /* m4svm_NewArray(Long, long) */
65 /* m4svm_NewArray(Float, float) */
66 /* m4svm_NewArray(Double, double) */
67
68 /* m4_undefine([:m4svm_NewArray:]) */
69
70 /*
71 ----------------------------------------------------------------------
72 m4svm_GetField
73 ----------------------------------------------------------------------
74 */
75 m4svm_define_begin v = ":], [:m4svm_GetField:])";
76
77 /*
78 -----------------------------------m4_dnl
79 -----------------------------------
80 Get$1Field
81 -----------------------------------m4_dnl
82 -----------------------------------
83 */
84
85 JNIEXPORT svm_static $2 JNICALL
Get$1Field(JNIEnv * _env,jobject obj,jfieldID fieldID)86 Get$1Field (JNIEnv *_env, jobject obj, jfieldID fieldID)
87 {
88 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
89 _svmt_field_info *field = fieldID;
90 $2 value;
91
92 assert (env == _svmf_get_current_env ());
93
94 _svmm_resuming_java (env);
95
96 {
97 size_t offset = field->data.instance_field.offset;
98
99 value = _svmf_get_$3_field (*obj, offset);
100 }
101
102 _svmm_stopping_java (env);
103
104 return value;
105 }
106
107 m4svm_define_end v = ":])";
108
109 /* m4svm_GetField(Boolean, jboolean, BOOLEAN) */
110 /* m4svm_GetField(Byte, jbyte, BYTE) */
111 /* m4svm_GetField(Short, jshort, SHORT) */
112 /* m4svm_GetField(Char, jchar, CHAR) */
113 /* m4svm_GetField(Int, jint, INT) */
114 /* m4svm_GetField(Long, jlong, LONG) */
115 /* m4svm_GetField(Float, jfloat, FLOAT) */
116 /* m4svm_GetField(Double, jdouble, DOUBLE) */
117
118 /* m4_undefine([:m4svm_GetField:]) */
119
120 /*
121 ----------------------------------------------------------------------
122 m4svm_SetField
123 ----------------------------------------------------------------------
124 */
125
126 m4svm_define_begin v = ":], [:m4svm_SetField:])";
127
128 /*
129 -----------------------------------m4_dnl
130 -----------------------------------
131 Set$1Field
132 -----------------------------------m4_dnl
133 -----------------------------------
134 */
135
136 JNIEXPORT svm_static void JNICALL
Set$1Field(JNIEnv * _env,jobject obj,jfieldID fieldID,$2 value)137 Set$1Field (JNIEnv *_env, jobject obj, jfieldID fieldID, $2 value)
138 {
139 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
140 _svmt_field_info *field = fieldID;
141
142 assert (env == _svmf_get_current_env ());
143
144 _svmm_resuming_java (env);
145
146 {
147 size_t offset = field->data.instance_field.offset;
148
149 _svmf_put_$3_field (*obj, offset, value);
150 }
151
152 _svmm_stopping_java (env);
153 }
154
155 m4svm_define_end v = ":])";
156
157 /* m4svm_SetField(Boolean, jboolean, BOOLEAN) */
158 /* m4svm_SetField(Byte, jbyte, BYTE) */
159 /* m4svm_SetField(Short, jshort, SHORT) */
160 /* m4svm_SetField(Char, jchar, CHAR) */
161 /* m4svm_SetField(Int, jint, INT) */
162 /* m4svm_SetField(Long, jlong, LONG) */
163 /* m4svm_SetField(Float, jfloat, FLOAT) */
164 /* m4svm_SetField(Double, jdouble, DOUBLE) */
165
166 /* m4_undefine([:m4svm_SetField:]) */
167
168 /*
169 ----------------------------------------------------------------------
170 m4svm_GetStaticField
171 ----------------------------------------------------------------------
172 */
173
174 m4svm_define_begin v = ":], [:m4svm_GetStaticField:])";
175
176 /*
177 -----------------------------------m4_dnl
178 -----------------------------------
179 GetStatic$1Field
180 -----------------------------------m4_dnl
181 -----------------------------------
182 */
183
184 JNIEXPORT svm_static $2 JNICALL
GetStatic$1Field(JNIEnv * _env,jclass cls SVM_UNUSED,jfieldID fieldID)185 GetStatic$1Field (JNIEnv *_env, jclass cls SVM_UNUSED, jfieldID fieldID)
186 {
187 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
188 _svmt_field_info *field = fieldID;
189 $2 value;
190
191 assert (env == _svmf_get_current_env ());
192
193 _svmm_resuming_java (env);
194
195 value = field->data.class_field.value.$3;
196
197 _svmm_stopping_java (env);
198
199 return value;
200 }
201
202 m4svm_define_end v = ":])";
203
204 /* m4svm_GetStaticField(Boolean, jboolean, z) */
205 /* m4svm_GetStaticField(Byte, jbyte, b) */
206 /* m4svm_GetStaticField(Short, jshort, s) */
207 /* m4svm_GetStaticField(Char, jchar, c) */
208 /* m4svm_GetStaticField(Int, jint, i) */
209 /* m4svm_GetStaticField(Long, jlong, j) */
210 /* m4svm_GetStaticField(Float, jfloat, f) */
211 /* m4svm_GetStaticField(Double, jdouble, d) */
212
213 /* m4_undefine([:m4svm_GetStaticField:]) */
214
215 /*
216 ----------------------------------------------------------------------
217 m4svm_SetStaticField
218 ----------------------------------------------------------------------
219 */
220
221 m4svm_define_begin v = ":], [:m4svm_SetStaticField:])";
222
223 /*
224 -----------------------------------m4_dnl
225 -----------------------------------
226 SetStatic$1Field
227 -----------------------------------m4_dnl
228 -----------------------------------
229 */
230
231 JNIEXPORT svm_static void JNICALL
SetStatic$1Field(JNIEnv * _env,jclass cls SVM_UNUSED,jfieldID fieldID,$2 value)232 SetStatic$1Field (JNIEnv *_env, jclass cls SVM_UNUSED, jfieldID fieldID,
233 $2 value)
234 {
235 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
236 _svmt_field_info *field = fieldID;
237
238 assert (env == _svmf_get_current_env ());
239
240 _svmm_resuming_java (env);
241
242 field->data.class_field.value.$3 = value;
243
244 _svmm_stopping_java (env);
245 }
246
247 m4svm_define_end v = ":])";
248
249 /* m4svm_SetStaticField(Boolean, jboolean, z) */
250 /* m4svm_SetStaticField(Byte, jbyte, b) */
251 /* m4svm_SetStaticField(Short, jshort, s) */
252 /* m4svm_SetStaticField(Char, jchar, c) */
253 /* m4svm_SetStaticField(Int, jint, i) */
254 /* m4svm_SetStaticField(Long, jlong, j) */
255 /* m4svm_SetStaticField(Float, jfloat, f) */
256 /* m4svm_SetStaticField(Double, jdouble, d) */
257
258 /* m4_undefine([:m4svm_SetStaticField:]) */
259
260 /*
261 ----------------------------------------------------------------------
262 m4svm_internal_CallNonvirtualMethod
263 ----------------------------------------------------------------------
264 */
265
266 m4svm_define_begin v = ":], [:m4svm_internal_CallNonvirtualMethod:])";
267
268 /*
269 -----------------------------------m4_dnl
270 -----------------------------------
271 _svmf_internal_CallNonvirtual$1Method$2
272 -----------------------------------m4_dnl
273 -----------------------------------
274 */
275
276 /* m4svm_comment_define([:m4svm_arglist:],
277 * [:[:methodID, m4_dnl
278 * m4_ifelse($:][:2, A, jvalue *args,
279 * $:][:2, V, va_list args)[::]m4_dnl
280 * :]:]) */
281 JNIEXPORT svm_static $3 JNICALL
_svmf_internal_CallNonvirtual$1Method$2(_svmt_JNIEnv * env,jobject this,jclass class SVM_UNUSED,jmethodID m4svm_arglist)282 _svmf_internal_CallNonvirtual$1Method$2 (_svmt_JNIEnv *env, jobject this,
283 jclass class SVM_UNUSED,
284 jmethodID m4svm_arglist)
285 {
286 _svmt_JavaVM *vm = env->vm;
287 _svmt_stack_frame *initial_frame;
288 _svmt_method_info *method = methodID;
289 _svmt_method_frame_info *frame_info = method->frame_info;
290 /* m4svm_comment_define([:m4svm_result_decl:],
291 * [:[:m4_ifelse(
292 * $:][:1, Void, ,
293 * $:][:1, Object, $:][:3 result = NULL;
294 * ,
295 * $:][:3 result = 0;
296 * )m4_:][:dnl:]:]) */
297 m4svm_result_decl dummy;
298
299 if (this == NULL)
300 {
301 _svmf_error_NullPointerException (env);
302 goto end;
303 }
304
305 /* assert (_svmf_is_set_flag
306 (method->class_info->state, SVM_TYPE_STATE_INITIALIZED)); */
307
308 /* syncronized? */
309 if (method->synchronized)
310 {
311 if (_svmf_enter_object_monitor (env, *(this)) != JNI_OK)
312 {
313 goto end;
314 }
315 }
316
317 if (_svmf_ensure_stack_capacity
318 (env, frame_info->internal_invoke_frame_size) != JNI_OK)
319 {
320 goto end;
321 }
322
323 initial_frame = env->stack.current_frame;
324
325 /* setup internal call frame */
326 {
327 size_t offset = env->stack.current_frame->end_offset;
328 _svmt_stack_frame *frame = (_svmt_stack_frame *) (void *)
329 (((char *) env->stack.current_frame) + offset);
330
331 frame->previous_offset = offset;
332 frame->end_offset = _svmf_aligned_size_t (sizeof (_svmt_stack_frame));
333 frame->method = &vm->internal_call_method;
334 frame->stack_trace_element = NULL;
335 frame->lock_count = 0;
336 frame->this = NULL;
337 frame->pc = vm->internal_call_method.frame_info->code;
338 frame->stack_size = 0;
339
340 env->stack.current_frame = frame;
341 }
342
343 /* push parameters */
344 {
345 _svmt_stack_frame *prev_frame = env->stack.current_frame;
346 _svmt_stack_value *locals = (_svmt_stack_value *) (void *)
347 (((char *) prev_frame) + prev_frame->end_offset);
348 jint i = 0;
349 char *descriptor = DREF (method->descriptor, value);
350 char c;
351 jint current = 0;
352 /* m4svm_comment_define([:m4svm_arg_decl:],
353 * [:[:m4_ifelse(
354 * $:][:2, A, jint arg = 0;
355 * ,
356 * )m4_:][:dnl:]:]) */
357 m4svm_arg_decl dummy;
358
359 locals[i++].reference = *this;
360
361 while ((c = descriptor[++current]) != '[:):]')
362 {
363 switch (c)
364 {
365 case 'Z':
366 {
367 /* m4svm_comment_define([:m4svm_arg_comment:],
368 * [:[:m4_ifelse(
369 * $:][:2, A, locals,
370 * /[::]* Take into account ISO C's default argument promotion. *[::]/
371 * locals)[::]m4_dnl
372 * :]:]) */
373 /* m4svm_comment_define([:m4svm_arg:],
374 * [:[:m4_ifelse(
375 * $:][:2, A, args[arg++].z,
376 * va_arg (args, jint))[::]m4_dnl
377 * :]:]) */
378 m4svm_arg_comment[i++].jint = m4svm_arg;
379 }
380 break;
381
382 case 'B':
383 {
384 /* m4svm_comment_define([:m4svm_arg_comment:],
385 * [:[:m4_ifelse(
386 * $:][:2, A, locals,
387 * /[::]* Take into account ISO C's default argument promotion. *[::]/
388 * locals)[::]m4_dnl
389 * :]:]) */
390 /* m4svm_comment_define([:m4svm_arg:],
391 * [:[:m4_ifelse(
392 * $:][:2, A, args[arg++].b,
393 * va_arg (args, jint))[::]m4_dnl
394 * :]:]) */
395 m4svm_arg_comment[i++].jint = m4svm_arg;
396 }
397 break;
398
399 case 'S':
400 {
401 /* m4svm_comment_define([:m4svm_arg_comment:],
402 * [:[:m4_ifelse(
403 * $:][:2, A, locals,
404 * /[::]* Take into account ISO C's default argument promotion. *[::]/
405 * locals)[::]m4_dnl
406 * :]:]) */
407 /* m4svm_comment_define([:m4svm_arg:],
408 * [:[:m4_ifelse(
409 * $:][:2, A, args[arg++].s,
410 * va_arg (args, jint))[::]m4_dnl
411 * :]:]) */
412 m4svm_arg_comment[i++].jint = m4svm_arg;
413 }
414 break;
415
416 case 'C':
417 {
418 /* m4svm_comment_define([:m4svm_arg_comment:],
419 * [:[:m4_ifelse(
420 * $:][:2, A, locals,
421 * /[::]* Take into account ISO C's default argument promotion. *[::]/
422 * locals)[::]m4_dnl
423 * :]:]) */
424 /* m4svm_comment_define([:m4svm_arg:],
425 * [:[:m4_ifelse(
426 * $:][:2, A, args[arg++].c,
427 * va_arg (args, int))[::]m4_dnl
428 * :]:]) */
429 m4svm_arg_comment[i++].jint = m4svm_arg;
430 }
431 break;
432
433 case 'I':
434 {
435 /* m4svm_comment_define([:m4svm_arg:],
436 * [:[:m4_ifelse(
437 * $:][:2, A, args[arg++].i,
438 * va_arg (args, jint))[::]m4_dnl
439 * :]:]) */
440 locals[i++].jint = m4svm_arg;
441 }
442 break;
443
444 case 'J':
445 {
446 /* m4svm_comment_define([:m4svm_arg:],
447 * [:[:m4_ifelse(
448 * $:][:2, A, args[arg++].j,
449 * va_arg (args, jlong))[::]m4_dnl
450 * :]:]) */
451 *((jlong *) (void *) &locals[i]) = m4svm_arg;
452 i += 2;
453 }
454 break;
455
456 case 'F':
457 {
458 /* m4svm_comment_define([:m4svm_arg_comment:],
459 * [:[:m4_ifelse(
460 * $:][:2, A, locals,
461 * /[::]* Take into account ISO C's default argument promotion. *[::]/
462 * locals)[::]m4_dnl
463 * :]:]) */
464 /* m4svm_comment_define([:m4svm_arg:],
465 * [:[:m4_ifelse(
466 * $:][:2, A, args[arg++].f,
467 * va_arg (args, jdouble))[::]m4_dnl
468 * :]:]) */
469 m4svm_arg_comment[i++].jfloat = m4svm_arg;
470 }
471 break;
472
473 case 'D':
474 {
475 /* m4svm_comment_define([:m4svm_arg:],
476 * [:[:m4_ifelse(
477 * $:][:2, A, args[arg++].d,
478 * va_arg (args, jdouble))[::]m4_dnl
479 * :]:]) */
480 *((jdouble *) (void *) &locals[i]) = m4svm_arg;
481 i += 2;
482 }
483 break;
484
485 case 'L':
486 {
487 /* m4svm_comment_define([:m4svm_arg:],
488 * [:[:m4_ifelse(
489 * $:][:2, A, args[arg++].l,
490 * va_arg (args, jobject))[::]m4_dnl
491 * :]:]) */
492 jobject obj = m4svm_arg;
493 #if defined (MAGIC)
494 assert ((obj ==
495 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
496 "SableVM") == 0));
497 #endif
498 locals[i++].reference = (obj == NULL) ? NULL : *obj;
499 while (descriptor[++current] != ';');
500 }
501 break;
502
503 case '[':
504 {
505 /* m4svm_comment_define([:m4svm_arg:],
506 * [:[:m4_ifelse(
507 * $:][:2, A, args[arg++].l,
508 * va_arg (args, jobject))[::]m4_dnl
509 * :]:]) */
510 jobject obj = m4svm_arg;
511 #if defined (MAGIC)
512 assert ((obj ==
513 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
514 "SableVM") == 0));
515 #endif
516 locals[i++].reference = (obj == NULL) ? NULL : *obj;
517 while (descriptor[++current] == '[');
518 if (descriptor[current] == 'L')
519 {
520 while (descriptor[++current] != ';');
521 }
522 }
523 break;
524
525 default:
526 {
527 _svmm_fatal_error ("impossible control flow");
528 }
529 break;
530 }
531 }
532
533 {
534 jint ref_count = frame_info->non_parameter_ref_locals_count;
535 jint j;
536
537 for (j = 0; j < ref_count; j++)
538 {
539 locals[i++].reference = NULL;
540 }
541 }
542 }
543
544 /* setup java call frame */
545 {
546 size_t offset =
547 env->stack.current_frame->end_offset + frame_info->start_offset;
548 _svmt_stack_frame *frame =
549 (_svmt_stack_frame *) (void *) (((char *) env->stack.current_frame) +
550 offset);
551
552 frame->previous_offset = offset;
553 frame->end_offset = frame_info->end_offset;
554 frame->method = method;
555 frame->stack_trace_element = NULL;
556 frame->lock_count = 0;
557 frame->this = *this;
558 frame->pc = frame_info->code;
559 frame->stack_size = 0;
560
561 env->stack.current_frame = frame;
562 }
563
564 /* interpret and pop internal call frame */
565 {
566 /* call the interpreter */
567 jint status = _svmf_interpreter (env);
568
569 /* retrieve stack frame */
570 _svmt_stack_frame *frame = env->stack.current_frame;
571
572 assert (frame->method == &vm->internal_call_method);
573
574 /* pop frame */
575 env->stack.current_frame = (_svmt_stack_frame *) (void *)
576 (((char *) frame) - frame->previous_offset);
577
578 /* rethrow exception */
579 if (status != JNI_OK)
580 {
581 goto end;
582 }
583 /* m4svm_comment_define([:m4svm_returnvalue:],
584 * [:[:m4svm_returnvalue_1($:][:3):]m4_dnl:]) */
585 /* m4svm_comment_define([:m4svm_returnvalue_1:],
586 * [:m4_ifelse($1, void, ,
587 * [:
588 * /[::]* set the return value *[::]/
589 * {
590 * _svmt_stack_value *ptr_ret = (_svmt_stack_value *) (void *)
591 * (((char *) frame) + frame->end_offset);
592 *
593 * m4_ifelse(
594 *
595 * $1, jlong,
596 * [:result = *((jlong *) (void *) ptr_ret);:],
597 *
598 * $1, jfloat,
599 * [:result = ptr_ret->jfloat;:],
600 *
601 * $1, jdouble,
602 * [:result = *((jdouble *) (void *) ptr_ret);:],
603 *
604 * $1, jobject,
605 * [:if (ptr_ret->reference != NULL)
606 * {
607 * _svmt_object_instance *ref = ptr_ret->reference;
608 * #if defined (MAGIC)
609 * assert (strcmp(ptr_ret->reference->magic, "SableVM") == 0);
610 * #endif
611 * result = _svmf_get_jni_frame_native_local (env);
612 * *result = ref;
613 * }:],
614 *
615 * [:result = ptr_ret->jint;:])
616 * }:]):]) */
617 m4svm_returnvalue = dummy;
618
619 }
620
621 end:
622 /* m4svm_comment_define([:m4svm_result_return:],
623 * [:[:m4_ifelse(
624 * $:][:1, Void, ;
625 * ,
626 * [::]
627 * return result;
628 * )m4:][:_dnl:]:]) */
629 m4svm_result_return dummy;
630
631 }
632
633 m4svm_define_end v = ":])";
634
635 /* m4svm_internal_CallNonvirtualMethod(Void, A, void) */
636 /* m4svm_internal_CallNonvirtualMethod(Void, V, void) */
637
638 /* m4svm_internal_CallNonvirtualMethod(Object, A, jobject) */
639 /* m4svm_internal_CallNonvirtualMethod(Object, V, jobject) */
640
641 /* m4svm_internal_CallNonvirtualMethod(Boolean, A, jboolean) */
642 /* m4svm_internal_CallNonvirtualMethod(Boolean, V, jboolean) */
643
644 /* m4svm_internal_CallNonvirtualMethod(Byte, A, jbyte) */
645 /* m4svm_internal_CallNonvirtualMethod(Byte, V, jbyte) */
646
647 /* m4svm_internal_CallNonvirtualMethod(Short, A, jshort) */
648 /* m4svm_internal_CallNonvirtualMethod(Short, V, jshort) */
649
650 /* m4svm_internal_CallNonvirtualMethod(Char, A, jchar) */
651 /* m4svm_internal_CallNonvirtualMethod(Char, V, jchar) */
652
653 /* m4svm_internal_CallNonvirtualMethod(Int, A, jint) */
654 /* m4svm_internal_CallNonvirtualMethod(Int, V, jint) */
655
656 /* m4svm_internal_CallNonvirtualMethod(Long, A, jlong) */
657 /* m4svm_internal_CallNonvirtualMethod(Long, V, jlong) */
658
659 /* m4svm_internal_CallNonvirtualMethod(Float, A, jfloat) */
660 /* m4svm_internal_CallNonvirtualMethod(Float, V, jfloat) */
661
662 /* m4svm_internal_CallNonvirtualMethod(Double, A, jdouble) */
663 /* m4svm_internal_CallNonvirtualMethod(Double, V, jdouble) */
664
665 /* m4_undefine([:m4svm_internal_CallNonvirtualMethod:]) */
666
667 /*
668 ----------------------------------------------------------------------
669 m4svm_CallNonvirtualMethod
670 ----------------------------------------------------------------------
671 */
672
673 m4svm_define_begin v = ":], [:m4svm_CallNonvirtualMethod:])";
674
675 /*
676 -----------------------------------m4_dnl
677 -----------------------------------
678 CallNonvirtual$1Method$2
679 -----------------------------------m4_dnl
680 -----------------------------------
681 */
682
683 /* m4svm_comment_define([:m4svm_arglist:],
684 * [:[:methodID, m4_dnl
685 * m4_ifelse($:][:2, , ...,
686 * $:][:2, A, jvalue *args,
687 * $:][:2, V, va_list args)[::]m4_dnl
688 * :]:]) */
689 JNIEXPORT svm_static $3 JNICALL
CallNonvirtual$1Method$2(JNIEnv * _env,jobject this,jclass class,jmethodID m4svm_arglist)690 CallNonvirtual$1Method$2 (JNIEnv *_env, jobject this, jclass class,
691 jmethodID m4svm_arglist)
692 {
693 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
694 /* m4svm_comment_define([:m4svm_result_decl:],
695 * [:[:m4_ifelse(
696 * $:][:1, Void, ,
697 * $:][:1, Object, $:][:3 result;
698 * ,
699 * $:][:3 result;
700 * )m4_:][:dnl:]:]) */
701 m4svm_result_decl dummy;
702
703 assert (env == _svmf_get_current_env ());
704
705 _svmm_resuming_java (env);
706
707 {
708 /* m4svm_comment_define([:m4svm_arg_decl:],
709 * [:[:m4_ifelse(
710 * $:][:2, , va_list args;
711 *
712 * va_start (args, methodID);
713 *
714 * m4_ifelse(
715 * $:][:1, Void,
716 * ,
717 * result = )m4_dnl
718 * _svmf_internal_CallNonvirtual$:][:1Method$:][:2V,
719 * m4_ifelse(
720 * $:][:1, Void,
721 * ,
722 * result = )m4_dnl
723 * _svmf_internal_CallNonvirtual$:][:1Method$:][:2):]:]) */
724 m4svm_arg_decl (env, this, class, methodID, args);
725 /* m4svm_comment_define([:m4svm_arg_end:],
726 * [:[:m4_ifelse(
727 * $:][:2, ,[::]
728 * va_end (args);,)m4_:][:dnl:]:]) */
729 m4svm_arg_end = dummy;
730
731 }
732
733 _svmm_stopping_java (env);
734 /* m4svm_comment_define([:m4svm_result_return:],
735 * [:[:m4_ifelse(
736 * $:][:1, Void, ,
737 * [::]
738 * return result;
739 * )m4:][:_dnl:]:]) */
740 m4svm_result_return dummy;
741
742 }
743
744 m4svm_define_end v = ":])";
745
746 /* m4svm_CallNonvirtualMethod(Void, , void) */
747 /* m4svm_CallNonvirtualMethod(Void, A, void) */
748 /* m4svm_CallNonvirtualMethod(Void, V, void) */
749
750 /* m4svm_CallNonvirtualMethod(Object, , jobject) */
751 /* m4svm_CallNonvirtualMethod(Object, A, jobject) */
752 /* m4svm_CallNonvirtualMethod(Object, V, jobject) */
753
754 /* m4svm_CallNonvirtualMethod(Boolean, , jboolean) */
755 /* m4svm_CallNonvirtualMethod(Boolean, A, jboolean) */
756 /* m4svm_CallNonvirtualMethod(Boolean, V, jboolean) */
757
758 /* m4svm_CallNonvirtualMethod(Byte, , jbyte) */
759 /* m4svm_CallNonvirtualMethod(Byte, A, jbyte) */
760 /* m4svm_CallNonvirtualMethod(Byte, V, jbyte) */
761
762 /* m4svm_CallNonvirtualMethod(Short, , jshort) */
763 /* m4svm_CallNonvirtualMethod(Short, A, jshort) */
764 /* m4svm_CallNonvirtualMethod(Short, V, jshort) */
765
766 /* m4svm_CallNonvirtualMethod(Char, , jchar) */
767 /* m4svm_CallNonvirtualMethod(Char, A, jchar) */
768 /* m4svm_CallNonvirtualMethod(Char, V, jchar) */
769
770 /* m4svm_CallNonvirtualMethod(Int, , jint) */
771 /* m4svm_CallNonvirtualMethod(Int, A, jint) */
772 /* m4svm_CallNonvirtualMethod(Int, V, jint) */
773
774 /* m4svm_CallNonvirtualMethod(Long, , jlong) */
775 /* m4svm_CallNonvirtualMethod(Long, A, jlong) */
776 /* m4svm_CallNonvirtualMethod(Long, V, jlong) */
777
778 /* m4svm_CallNonvirtualMethod(Float, , jfloat) */
779 /* m4svm_CallNonvirtualMethod(Float, A, jfloat) */
780 /* m4svm_CallNonvirtualMethod(Float, V, jfloat) */
781
782 /* m4svm_CallNonvirtualMethod(Double, , jdouble) */
783 /* m4svm_CallNonvirtualMethod(Double, A, jdouble) */
784 /* m4svm_CallNonvirtualMethod(Double, V, jdouble) */
785
786 /* m4_undefine([:m4svm_CallNonvirtualMethod:]) */
787
788 /*
789 ----------------------------------------------------------------------
790 m4svm_CallMethod
791 ----------------------------------------------------------------------
792 */
793
794 m4svm_define_begin v = ":], [:m4svm_CallMethod:])";
795
796 /*
797 -----------------------------------m4_dnl
798 -----------------------------------
799 Call$1Method$2
800 -----------------------------------m4_dnl
801 -----------------------------------
802 */
803
804 /* m4svm_comment_define([:m4svm_arglist:],
805 * [:[:methodID, m4_dnl
806 * m4_ifelse($:][:2, , ...,
807 * $:][:2, A, jvalue *args,
808 * $:][:2, V, va_list args)[::]m4_dnl
809 * :]:]) */
810 JNIEXPORT svm_static $3 JNICALL
Call$1Method$2(JNIEnv * _env,jobject this,jmethodID m4svm_arglist)811 Call$1Method$2 (JNIEnv *_env, jobject this, jmethodID m4svm_arglist)
812 {
813 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
814 /* m4svm_comment_define([:m4svm_result_decl:],
815 * [:[:m4_ifelse(
816 * $:][:1, Void, ,
817 * $:][:1, Object, $:][:3 result = NULL;
818 * ,
819 * $:][:3 result = 0;
820 * )m4_:][:dnl:]:]) */
821 m4svm_result_decl dummy;
822
823 assert (env == _svmf_get_current_env ());
824
825 _svmm_resuming_java (env);
826
827 {
828 _svmt_JavaVM *vm = env->vm;
829 _svmt_stack_frame *initial_frame;
830 _svmt_method_info *method;
831 _svmt_method_frame_info *frame_info;
832 size_t method_offset;
833
834 if (this == NULL)
835 {
836 _svmf_error_NullPointerException (env);
837 goto end;
838 }
839
840 if (_svmf_is_set_flag
841 (methodID->class_info->access_flags, SVM_ACC_INTERFACE))
842 {
843 /* interface */
844 method_offset = -((1 + methodID->method_id) *
845 sizeof (_svmt_method_info *));
846 }
847 else
848 {
849 /* class */
850 method_offset = sizeof (_svmt_vtable) +
851 (methodID->method_id * sizeof (_svmt_method_info *));
852 }
853
854 method = *((_svmt_method_info **) (void *)
855 (((char *) (*this)->vtable) + method_offset));
856
857 frame_info = method->frame_info;
858
859 /* assert (_svmf_is_set_flag
860 (method->class_info->state, SVM_TYPE_STATE_INITIALIZED)); */
861
862 /* syncronized? */
863 if (method->synchronized)
864 {
865 if (_svmf_enter_object_monitor (env, *(this)) != JNI_OK)
866 {
867 goto end;
868 }
869 }
870
871 if (_svmf_ensure_stack_capacity
872 (env, frame_info->internal_invoke_frame_size) != JNI_OK)
873 {
874 goto end;
875 }
876
877 initial_frame = env->stack.current_frame;
878
879 /* setup internal call frame */
880 {
881 size_t offset = env->stack.current_frame->end_offset;
882 _svmt_stack_frame *frame = (_svmt_stack_frame *) (void *)
883 (((char *) env->stack.current_frame) + offset);
884
885 frame->previous_offset = offset;
886 frame->end_offset = _svmf_aligned_size_t (sizeof (_svmt_stack_frame));
887 frame->method = &vm->internal_call_method;
888 frame->stack_trace_element = NULL;
889 frame->lock_count = 0;
890 frame->this = NULL;
891 frame->pc = vm->internal_call_method.frame_info->code;
892 frame->stack_size = 0;
893
894 env->stack.current_frame = frame;
895 }
896
897 /* push parameters */
898 {
899 _svmt_stack_frame *prev_frame = env->stack.current_frame;
900 _svmt_stack_value *locals = (_svmt_stack_value *) (void *)
901 (((char *) prev_frame) + prev_frame->end_offset);
902 jint i = 0;
903 char *descriptor = DREF (method->descriptor, value);
904 char c;
905 jint current = 0;
906 /* m4svm_comment_define([:m4svm_arg_decl:],
907 * [:[:m4_ifelse(
908 * $:][:2, , va_list args;
909 *
910 * va_start (args, methodID);
911 * ,
912 * $:][:2, A, jint arg = 0;
913 * ,
914 * )m4_:][:dnl:]:]) */
915 m4svm_arg_decl dummy;
916
917 locals[i++].reference = *this;
918
919 while ((c = descriptor[++current]) != '[:):]')
920 {
921 switch (c)
922 {
923 case 'Z':
924 {
925 /* m4svm_comment_define([:m4svm_arg_comment:],
926 * [:[:m4_ifelse(
927 * $:][:2, A, locals,
928 * /[::]* Take into account ISO C's default argument promotion. *[::]/
929 * locals)[::]m4_dnl
930 * :]:]) */
931 /* m4svm_comment_define([:m4svm_arg:],
932 * [:[:m4_ifelse(
933 * $:][:2, A, args[arg++].z,
934 * va_arg (args, jint))[::]m4_dnl
935 * :]:]) */
936 m4svm_arg_comment[i++].jint = m4svm_arg;
937 }
938 break;
939
940 case 'B':
941 {
942 /* m4svm_comment_define([:m4svm_arg_comment:],
943 * [:[:m4_ifelse(
944 * $:][:2, A, locals,
945 * /[::]* Take into account ISO C's default argument promotion. *[::]/
946 * locals)[::]m4_dnl
947 * :]:]) */
948 /* m4svm_comment_define([:m4svm_arg:],
949 * [:[:m4_ifelse(
950 * $:][:2, A, args[arg++].b,
951 * va_arg (args, jint))[::]m4_dnl
952 * :]:]) */
953 m4svm_arg_comment[i++].jint = m4svm_arg;
954 }
955 break;
956
957 case 'S':
958 {
959 /* m4svm_comment_define([:m4svm_arg_comment:],
960 * [:[:m4_ifelse(
961 * $:][:2, A, locals,
962 * /[::]* Take into account ISO C's default argument promotion. *[::]/
963 * locals)[::]m4_dnl
964 * :]:]) */
965 /* m4svm_comment_define([:m4svm_arg:],
966 * [:[:m4_ifelse(
967 * $:][:2, A, args[arg++].s,
968 * va_arg (args, jint))[::]m4_dnl
969 * :]:]) */
970 m4svm_arg_comment[i++].jint = m4svm_arg;
971 }
972 break;
973
974 case 'C':
975 {
976 /* m4svm_comment_define([:m4svm_arg_comment:],
977 * [:[:m4_ifelse(
978 * $:][:2, A, locals,
979 * /[::]* Take into account ISO C's default argument promotion. *[::]/
980 * locals)[::]m4_dnl
981 * :]:]) */
982 /* m4svm_comment_define([:m4svm_arg:],
983 * [:[:m4_ifelse(
984 * $:][:2, A, args[arg++].c,
985 * va_arg (args, int))[::]m4_dnl
986 * :]:]) */
987 m4svm_arg_comment[i++].jint = m4svm_arg;
988 }
989 break;
990
991 case 'I':
992 {
993 /* m4svm_comment_define([:m4svm_arg:],
994 * [:[:m4_ifelse(
995 * $:][:2, A, args[arg++].i,
996 * va_arg (args, jint))[::]m4_dnl
997 * :]:]) */
998 locals[i++].jint = m4svm_arg;
999 }
1000 break;
1001
1002 case 'J':
1003 {
1004 /* m4svm_comment_define([:m4svm_arg:],
1005 * [:[:m4_ifelse(
1006 * $:][:2, A, args[arg++].j,
1007 * va_arg (args, jlong))[::]m4_dnl
1008 * :]:]) */
1009 *((jlong *) (void *) &locals[i]) = m4svm_arg;
1010 i += 2;
1011 }
1012 break;
1013
1014 case 'F':
1015 {
1016 /* m4svm_comment_define([:m4svm_arg_comment:],
1017 * [:[:m4_ifelse(
1018 * $:][:2, A, locals,
1019 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1020 * locals)[::]m4_dnl
1021 * :]:]) */
1022 /* m4svm_comment_define([:m4svm_arg:],
1023 * [:[:m4_ifelse(
1024 * $:][:2, A, args[arg++].f,
1025 * va_arg (args, jdouble))[::]m4_dnl
1026 * :]:]) */
1027 m4svm_arg_comment[i++].jfloat = m4svm_arg;
1028 }
1029 break;
1030
1031 case 'D':
1032 {
1033 /* m4svm_comment_define([:m4svm_arg:],
1034 * [:[:m4_ifelse(
1035 * $:][:2, A, args[arg++].d,
1036 * va_arg (args, jdouble))[::]m4_dnl
1037 * :]:]) */
1038 *((jdouble *) (void *) &locals[i]) = m4svm_arg;
1039 i += 2;
1040 }
1041 break;
1042
1043 case 'L':
1044 {
1045 /* m4svm_comment_define([:m4svm_arg:],
1046 * [:[:m4_ifelse(
1047 * $:][:2, A, args[arg++].l,
1048 * va_arg (args, jobject))[::]m4_dnl
1049 * :]:]) */
1050 jobject obj = m4svm_arg;
1051 #if defined (MAGIC)
1052 assert ((obj ==
1053 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
1054 "SableVM") == 0));
1055 #endif
1056 locals[i++].reference = (obj == NULL) ? NULL : *obj;
1057 while (descriptor[++current] != ';');
1058 }
1059 break;
1060
1061 case '[':
1062 {
1063 /* m4svm_comment_define([:m4svm_arg:],
1064 * [:[:m4_ifelse(
1065 * $:][:2, A, args[arg++].l,
1066 * va_arg (args, jobject))[::]m4_dnl
1067 * :]:]) */
1068 jobject obj = m4svm_arg;
1069 #if defined (MAGIC)
1070 assert ((obj ==
1071 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
1072 "SableVM") == 0));
1073 #endif
1074 locals[i++].reference = (obj == NULL) ? NULL : *obj;
1075 while (descriptor[++current] == '[');
1076 if (descriptor[current] == 'L')
1077 {
1078 while (descriptor[++current] != ';');
1079 }
1080 }
1081 break;
1082
1083 default:
1084 {
1085 _svmm_fatal_error ("impossible control flow");
1086 }
1087 break;
1088 }
1089 }
1090
1091 /* m4svm_comment_define([:m4svm_arg_end:],
1092 * [:[:m4_ifelse(
1093 * $:][:2, , va_end (args);
1094 * ,
1095 * )m4_:][:dnl:]:]) */
1096 m4svm_arg_end = dummy;
1097
1098 {
1099 jint ref_count = frame_info->non_parameter_ref_locals_count;
1100 jint j;
1101
1102 for (j = 0; j < ref_count; j++)
1103 {
1104 locals[i++].reference = NULL;
1105 }
1106 }
1107 }
1108
1109 /* setup java call frame */
1110 {
1111 size_t offset =
1112 env->stack.current_frame->end_offset + frame_info->start_offset;
1113 _svmt_stack_frame *frame =
1114 (_svmt_stack_frame *) (void *) (((char *) env->stack.current_frame) +
1115 offset);
1116
1117 frame->previous_offset = offset;
1118 frame->end_offset = frame_info->end_offset;
1119 frame->method = method;
1120 frame->stack_trace_element = NULL;
1121 frame->lock_count = 0;
1122 frame->this = *this;
1123 frame->pc = frame_info->code;
1124 frame->stack_size = 0;
1125
1126 env->stack.current_frame = frame;
1127 }
1128
1129 /* interpret and pop internal call frame */
1130 {
1131 /* call the interpreter */
1132 jint status = _svmf_interpreter (env);
1133
1134 /* retrieve stack frame */
1135 _svmt_stack_frame *frame = env->stack.current_frame;
1136
1137 assert (frame->method == &vm->internal_call_method);
1138
1139 /* pop frame */
1140 env->stack.current_frame = (_svmt_stack_frame *) (void *)
1141 (((char *) frame) - frame->previous_offset);
1142
1143 /* rethrow exception */
1144 if (status != JNI_OK)
1145 {
1146 goto end;
1147 }
1148 /* m4svm_comment_define([:m4svm_returnvalue:],
1149 * [:[:m4svm_returnvalue_1($:][:3):]m4_dnl:]) */
1150 /* m4svm_comment_define([:m4svm_returnvalue_1:],
1151 * [:m4_ifelse($1, void, ,
1152 * [:
1153 * /[::]* set the return value *[::]/
1154 * {
1155 * _svmt_stack_value *ptr_ret = (_svmt_stack_value *) (void *)
1156 * (((char *) frame) + frame->end_offset);
1157 *
1158 * m4_ifelse(
1159 *
1160 * $1, jlong,
1161 * [:result = *((jlong *) (void *) ptr_ret);:],
1162 *
1163 * $1, jfloat,
1164 * [:result = ptr_ret->jfloat;:],
1165 *
1166 * $1, jdouble,
1167 * [:result = *((jdouble *) (void *) ptr_ret);:],
1168 *
1169 * $1, jobject,
1170 * [:if (ptr_ret->reference != NULL)
1171 * {
1172 * _svmt_object_instance *ref = ptr_ret->reference;
1173 * #if defined (MAGIC)
1174 * assert (strcmp(ptr_ret->reference->magic, "SableVM") == 0);
1175 * #endif
1176 * result = _svmf_get_jni_frame_native_local (env);
1177 * *result = ref;
1178 * }:],
1179 *
1180 * [:result = ptr_ret->jint;:])
1181 * }:]):]) */
1182 m4svm_returnvalue = dummy;
1183
1184 }
1185 }
1186
1187 end:
1188 _svmm_stopping_java (env);
1189 /* m4svm_comment_define([:m4svm_result_return:],
1190 * [:[:m4_ifelse(
1191 * $:][:1, Void, ,
1192 * [::]
1193 * return result;
1194 * )m4:][:_dnl:]:]) */
1195 m4svm_result_return dummy;
1196
1197 }
1198
1199 m4svm_define_end v = ":])";
1200
1201 /* m4svm_CallMethod(Void, , void) */
1202 /* m4svm_CallMethod(Void, A, void) */
1203 /* m4svm_CallMethod(Void, V, void) */
1204
1205 /* m4svm_CallMethod(Object, , jobject) */
1206 /* m4svm_CallMethod(Object, A, jobject) */
1207 /* m4svm_CallMethod(Object, V, jobject) */
1208
1209 /* m4svm_CallMethod(Boolean, , jboolean) */
1210 /* m4svm_CallMethod(Boolean, A, jboolean) */
1211 /* m4svm_CallMethod(Boolean, V, jboolean) */
1212
1213 /* m4svm_CallMethod(Byte, , jbyte) */
1214 /* m4svm_CallMethod(Byte, A, jbyte) */
1215 /* m4svm_CallMethod(Byte, V, jbyte) */
1216
1217 /* m4svm_CallMethod(Short, , jshort) */
1218 /* m4svm_CallMethod(Short, A, jshort) */
1219 /* m4svm_CallMethod(Short, V, jshort) */
1220
1221 /* m4svm_CallMethod(Char, , jchar) */
1222 /* m4svm_CallMethod(Char, A, jchar) */
1223 /* m4svm_CallMethod(Char, V, jchar) */
1224
1225 /* m4svm_CallMethod(Int, , jint) */
1226 /* m4svm_CallMethod(Int, A, jint) */
1227 /* m4svm_CallMethod(Int, V, jint) */
1228
1229 /* m4svm_CallMethod(Long, , jlong) */
1230 /* m4svm_CallMethod(Long, A, jlong) */
1231 /* m4svm_CallMethod(Long, V, jlong) */
1232
1233 /* m4svm_CallMethod(Float, , jfloat) */
1234 /* m4svm_CallMethod(Float, A, jfloat) */
1235 /* m4svm_CallMethod(Float, V, jfloat) */
1236
1237 /* m4svm_CallMethod(Double, , jdouble) */
1238 /* m4svm_CallMethod(Double, A, jdouble) */
1239 /* m4svm_CallMethod(Double, V, jdouble) */
1240
1241 /* m4_undefine([:m4svm_CallMethod:]) */
1242
1243 /*
1244 ----------------------------------------------------------------------
1245 m4svm_CallStaticMethod
1246 ----------------------------------------------------------------------
1247 */
1248
1249 m4svm_define_begin v = ":], [:m4svm_CallStaticMethod:])";
1250
1251 /*
1252 -----------------------------------m4_dnl
1253 -----------------------------------
1254 CallStatic$1Method$2
1255 -----------------------------------m4_dnl
1256 -----------------------------------
1257 */
1258
1259 /* m4svm_comment_define([:m4svm_arglist:],
1260 * [:[:methodID, m4_dnl
1261 * m4_ifelse($:][:2, , ...,
1262 * $:][:2, A, jvalue *args,
1263 * $:][:2, V, va_list args)[::]m4_dnl
1264 * :]:]) */
1265 JNIEXPORT svm_static $3 JNICALL
CallStatic$1Method$2(JNIEnv * _env,jclass cls SVM_UNUSED,jmethodID m4svm_arglist)1266 CallStatic$1Method$2 (JNIEnv *_env, jclass cls SVM_UNUSED,
1267 jmethodID m4svm_arglist)
1268 {
1269 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1270 /* m4svm_comment_define([:m4svm_result_decl:],
1271 * [:[:m4_ifelse(
1272 * $:][:1, Void, ,
1273 * $:][:1, Object, $:][:3 result = NULL;
1274 * ,
1275 * $:][:3 result = 0;
1276 * )m4_:][:dnl:]:]) */
1277 m4svm_result_decl dummy;
1278
1279 assert (env == _svmf_get_current_env ());
1280
1281 _svmm_resuming_java (env);
1282
1283 {
1284 _svmt_JavaVM *vm = env->vm;
1285 _svmt_stack_frame *initial_frame;
1286 _svmt_method_info *method = methodID;
1287 _svmt_method_frame_info *frame_info = method->frame_info;
1288
1289 /* assert (_svmf_is_set_flag
1290 (method->class_info->state, SVM_TYPE_STATE_INITIALIZED)); */
1291
1292 /* syncronized? */
1293 if (method->synchronized)
1294 {
1295 if (_svmf_enter_object_monitor
1296 (env, *(method->class_info->class_instance)) != JNI_OK)
1297 {
1298 goto end;
1299 }
1300 }
1301
1302 if (_svmf_ensure_stack_capacity
1303 (env, frame_info->internal_invoke_frame_size) != JNI_OK)
1304 {
1305 goto end;
1306 }
1307
1308 initial_frame = env->stack.current_frame;
1309
1310 /* setup internal call frame */
1311 {
1312 size_t offset = env->stack.current_frame->end_offset;
1313 _svmt_stack_frame *frame = (_svmt_stack_frame *) (void *)
1314 (((char *) env->stack.current_frame) + offset);
1315
1316 frame->previous_offset = offset;
1317 frame->end_offset = _svmf_aligned_size_t (sizeof (_svmt_stack_frame));
1318 frame->method = &vm->internal_call_method;
1319 frame->stack_trace_element = NULL;
1320 frame->lock_count = 0;
1321 frame->this = NULL;
1322 frame->pc = vm->internal_call_method.frame_info->code;
1323 frame->stack_size = 0;
1324
1325 env->stack.current_frame = frame;
1326 }
1327
1328 /* push parameters */
1329 {
1330 _svmt_stack_frame *prev_frame = env->stack.current_frame;
1331 _svmt_stack_value *locals = (_svmt_stack_value *) (void *)
1332 (((char *) prev_frame) + prev_frame->end_offset);
1333 jint i = 0;
1334 char *descriptor = DREF (method->descriptor, value);
1335 char c;
1336 jint current = 0;
1337 /* m4svm_comment_define([:m4svm_arg_decl:],
1338 * [:[:m4_ifelse(
1339 * $:][:2, , va_list args;
1340 *
1341 * va_start (args, methodID);
1342 * ,
1343 * $:][:2, A, jint arg = 0;
1344 * ,
1345 * )m4_:][:dnl:]:]) */
1346 m4svm_arg_decl dummy;
1347
1348 while ((c = descriptor[++current]) != '[:):]')
1349 {
1350 switch (c)
1351 {
1352 case 'Z':
1353 {
1354 /* m4svm_comment_define([:m4svm_arg_comment:],
1355 * [:[:m4_ifelse(
1356 * $:][:2, A, locals,
1357 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1358 * locals)[::]m4_dnl
1359 * :]:]) */
1360 /* m4svm_comment_define([:m4svm_arg:],
1361 * [:[:m4_ifelse(
1362 * $:][:2, A, args[arg++].z,
1363 * va_arg (args, jint))[::]m4_dnl
1364 * :]:]) */
1365 m4svm_arg_comment[i++].jint = m4svm_arg;
1366 }
1367 break;
1368
1369 case 'B':
1370 {
1371 /* m4svm_comment_define([:m4svm_arg_comment:],
1372 * [:[:m4_ifelse(
1373 * $:][:2, A, locals,
1374 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1375 * locals)[::]m4_dnl
1376 * :]:]) */
1377 /* m4svm_comment_define([:m4svm_arg:],
1378 * [:[:m4_ifelse(
1379 * $:][:2, A, args[arg++].b,
1380 * va_arg (args, jint))[::]m4_dnl
1381 * :]:]) */
1382 m4svm_arg_comment[i++].jint = m4svm_arg;
1383 }
1384 break;
1385
1386 case 'S':
1387 {
1388 /* m4svm_comment_define([:m4svm_arg_comment:],
1389 * [:[:m4_ifelse(
1390 * $:][:2, A, locals,
1391 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1392 * locals)[::]m4_dnl
1393 * :]:]) */
1394 /* m4svm_comment_define([:m4svm_arg:],
1395 * [:[:m4_ifelse(
1396 * $:][:2, A, args[arg++].s,
1397 * va_arg (args, jint))[::]m4_dnl
1398 * :]:]) */
1399 m4svm_arg_comment[i++].jint = m4svm_arg;
1400 }
1401 break;
1402
1403 case 'C':
1404 {
1405 /* m4svm_comment_define([:m4svm_arg_comment:],
1406 * [:[:m4_ifelse(
1407 * $:][:2, A, locals,
1408 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1409 * locals)[::]m4_dnl
1410 * :]:]) */
1411 /* m4svm_comment_define([:m4svm_arg:],
1412 * [:[:m4_ifelse(
1413 * $:][:2, A, args[arg++].c,
1414 * va_arg (args, int))[::]m4_dnl
1415 * :]:]) */
1416 m4svm_arg_comment[i++].jint = m4svm_arg;
1417 }
1418 break;
1419
1420 case 'I':
1421 {
1422 /* m4svm_comment_define([:m4svm_arg:],
1423 * [:[:m4_ifelse(
1424 * $:][:2, A, args[arg++].i,
1425 * va_arg (args, jint))[::]m4_dnl
1426 * :]:]) */
1427 locals[i++].jint = m4svm_arg;
1428 }
1429 break;
1430
1431 case 'J':
1432 {
1433 /* m4svm_comment_define([:m4svm_arg:],
1434 * [:[:m4_ifelse(
1435 * $:][:2, A, args[arg++].j,
1436 * va_arg (args, jlong))[::]m4_dnl
1437 * :]:]) */
1438 *((jlong *) (void *) &locals[i]) = m4svm_arg;
1439 i += 2;
1440 }
1441 break;
1442
1443 case 'F':
1444 {
1445 /* m4svm_comment_define([:m4svm_arg_comment:],
1446 * [:[:m4_ifelse(
1447 * $:][:2, A, locals,
1448 * /[::]* Take into account ISO C's default argument promotion. *[::]/
1449 * locals)[::]m4_dnl
1450 * :]:]) */
1451 /* m4svm_comment_define([:m4svm_arg:],
1452 * [:[:m4_ifelse(
1453 * $:][:2, A, args[arg++].f,
1454 * va_arg (args, jdouble))[::]m4_dnl
1455 * :]:]) */
1456 m4svm_arg_comment[i++].jfloat = m4svm_arg;
1457 }
1458 break;
1459
1460 case 'D':
1461 {
1462 /* m4svm_comment_define([:m4svm_arg:],
1463 * [:[:m4_ifelse(
1464 * $:][:2, A, args[arg++].d,
1465 * va_arg (args, jdouble))[::]m4_dnl
1466 * :]:]) */
1467 *((jdouble *) (void *) &locals[i]) = m4svm_arg;
1468 i += 2;
1469 }
1470 break;
1471
1472 case 'L':
1473 {
1474 /* m4svm_comment_define([:m4svm_arg:],
1475 * [:[:m4_ifelse(
1476 * $:][:2, A, args[arg++].l,
1477 * va_arg (args, jobject))[::]m4_dnl
1478 * :]:]) */
1479 jobject obj = m4svm_arg;
1480 #if defined (MAGIC)
1481 assert ((obj ==
1482 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
1483 "SableVM") == 0));
1484 #endif
1485 locals[i++].reference = (obj == NULL) ? NULL : *obj;
1486 while (descriptor[++current] != ';');
1487 }
1488 break;
1489
1490 case '[':
1491 {
1492 /* m4svm_comment_define([:m4svm_arg:],
1493 * [:[:m4_ifelse(
1494 * $:][:2, A, args[arg++].l,
1495 * va_arg (args, jobject))[::]m4_dnl
1496 * :]:]) */
1497 jobject obj = m4svm_arg;
1498 #if defined (MAGIC)
1499 assert ((obj ==
1500 NULL) ? JNI_TRUE : (strcmp ((*obj)->magic,
1501 "SableVM") == 0));
1502 #endif
1503 locals[i++].reference = (obj == NULL) ? NULL : *obj;
1504 while (descriptor[++current] == '[');
1505 if (descriptor[current] == 'L')
1506 {
1507 while (descriptor[++current] != ';');
1508 }
1509 }
1510 break;
1511
1512 default:
1513 {
1514 _svmm_fatal_error ("impossible control flow");
1515 }
1516 break;
1517 }
1518 }
1519
1520 /* m4svm_comment_define([:m4svm_arg_end:],
1521 * [:[:m4_ifelse(
1522 * $:][:2, , va_end (args);
1523 * ,
1524 * )m4_:][:dnl:]:]) */
1525 m4svm_arg_end = dummy;
1526
1527 {
1528 jint ref_count = frame_info->non_parameter_ref_locals_count;
1529 jint j;
1530
1531 for (j = 0; j < ref_count; j++)
1532 {
1533 locals[i++].reference = NULL;
1534 }
1535 }
1536 }
1537
1538 /* setup java call frame */
1539 {
1540 size_t offset =
1541 env->stack.current_frame->end_offset + frame_info->start_offset;
1542 _svmt_stack_frame *frame =
1543 (_svmt_stack_frame *) (void *) (((char *) env->stack.current_frame) +
1544 offset);
1545
1546 frame->previous_offset = offset;
1547 frame->end_offset = frame_info->end_offset;
1548 frame->method = method;
1549 frame->stack_trace_element = NULL;
1550 frame->lock_count = 0;
1551 frame->this = *(method->class_info->class_instance);
1552 frame->pc = frame_info->code;
1553 frame->stack_size = 0;
1554
1555 env->stack.current_frame = frame;
1556 }
1557
1558 /* interpret and pop internal call frame */
1559 {
1560 /* call the interpreter */
1561 jint status = _svmf_interpreter (env);
1562
1563 /* retrieve stack frame */
1564 _svmt_stack_frame *frame = env->stack.current_frame;
1565
1566 assert (frame->method == &vm->internal_call_method);
1567
1568 /* pop frame */
1569 env->stack.current_frame = (_svmt_stack_frame *) (void *)
1570 (((char *) frame) - frame->previous_offset);
1571
1572 /* rethrow exception */
1573 if (status != JNI_OK)
1574 {
1575 goto end;
1576 }
1577 /* m4svm_comment_define([:m4svm_returnvalue:],
1578 * [:[:m4svm_returnvalue_1($:][:3):]m4_dnl:]) */
1579 /* m4svm_comment_define([:m4svm_returnvalue_1:],
1580 * [:m4_ifelse($1, void, ,
1581 * [:
1582 * /[::]* set the return value *[::]/
1583 * {
1584 * _svmt_stack_value *ptr_ret = (_svmt_stack_value *) (void *)
1585 * (((char *) frame) + frame->end_offset);
1586 *
1587 * m4_ifelse(
1588 *
1589 * $1, jlong,
1590 * [:result = *((jlong *) (void *) ptr_ret);:],
1591 *
1592 * $1, jfloat,
1593 * [:result = ptr_ret->jfloat;:],
1594 *
1595 * $1, jdouble,
1596 * [:result = *((jdouble *) (void *) ptr_ret);:],
1597 *
1598 * $1, jobject,
1599 * [:if (ptr_ret->reference != NULL)
1600 * {
1601 * _svmt_object_instance *ref = ptr_ret->reference;
1602 * #if defined (MAGIC)
1603 * assert (strcmp(ptr_ret->reference->magic, "SableVM") == 0);
1604 * #endif
1605 * result = _svmf_get_jni_frame_native_local (env);
1606 * *result = ref;
1607 * }:],
1608 *
1609 * [:result = ptr_ret->jint;:])
1610 * }:]):]) */
1611 m4svm_returnvalue = dummy;
1612
1613 }
1614 }
1615
1616 end:
1617 _svmm_stopping_java (env);
1618 /* m4svm_comment_define([:m4svm_result_return:],
1619 * [:[:m4_ifelse(
1620 * $:][:1, Void, ,
1621 * [::]
1622 * return result;
1623 * )m4:][:_dnl:]:]) */
1624 m4svm_result_return dummy;
1625
1626 }
1627
1628 m4svm_define_end v = ":])";
1629
1630 /* m4svm_CallStaticMethod(Void, , void) */
1631 /* m4svm_CallStaticMethod(Void, A, void) */
1632 /* m4svm_CallStaticMethod(Void, V, void) */
1633
1634 /* m4svm_CallStaticMethod(Object, , jobject) */
1635 /* m4svm_CallStaticMethod(Object, A, jobject) */
1636 /* m4svm_CallStaticMethod(Object, V, jobject) */
1637
1638 /* m4svm_CallStaticMethod(Boolean, , jboolean) */
1639 /* m4svm_CallStaticMethod(Boolean, A, jboolean) */
1640 /* m4svm_CallStaticMethod(Boolean, V, jboolean) */
1641
1642 /* m4svm_CallStaticMethod(Byte, , jbyte) */
1643 /* m4svm_CallStaticMethod(Byte, A, jbyte) */
1644 /* m4svm_CallStaticMethod(Byte, V, jbyte) */
1645
1646 /* m4svm_CallStaticMethod(Short, , jshort) */
1647 /* m4svm_CallStaticMethod(Short, A, jshort) */
1648 /* m4svm_CallStaticMethod(Short, V, jshort) */
1649
1650 /* m4svm_CallStaticMethod(Char, , jchar) */
1651 /* m4svm_CallStaticMethod(Char, A, jchar) */
1652 /* m4svm_CallStaticMethod(Char, V, jchar) */
1653
1654 /* m4svm_CallStaticMethod(Int, , jint) */
1655 /* m4svm_CallStaticMethod(Int, A, jint) */
1656 /* m4svm_CallStaticMethod(Int, V, jint) */
1657
1658 /* m4svm_CallStaticMethod(Long, , jlong) */
1659 /* m4svm_CallStaticMethod(Long, A, jlong) */
1660 /* m4svm_CallStaticMethod(Long, V, jlong) */
1661
1662 /* m4svm_CallStaticMethod(Float, , jfloat) */
1663 /* m4svm_CallStaticMethod(Float, A, jfloat) */
1664 /* m4svm_CallStaticMethod(Float, V, jfloat) */
1665
1666 /* m4svm_CallStaticMethod(Double, , jdouble) */
1667 /* m4svm_CallStaticMethod(Double, A, jdouble) */
1668 /* m4svm_CallStaticMethod(Double, V, jdouble) */
1669
1670 /* m4_undefine([:m4svm_CallStaticMethod:]) */
1671
1672 /*
1673 ----------------------------------------------------------------------
1674 m4svm_GetArrayRegion
1675 ----------------------------------------------------------------------
1676 */
1677
1678 m4svm_define_begin v = ":], [:m4svm_GetArrayRegion:])";
1679
1680 /*
1681 -----------------------------------m4_dnl
1682 -----------------------------------
1683 Get$1ArrayRegion
1684 -----------------------------------m4_dnl
1685 -----------------------------------
1686 */
1687
1688 JNIEXPORT svm_static void JNICALL
Get$1ArrayRegion(JNIEnv * _env,$2Array array,jsize start,jsize len,$2 * buf)1689 Get$1ArrayRegion (JNIEnv *_env, $2Array array, jsize start, jsize len,
1690 $2 * buf)
1691 {
1692 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1693
1694 assert (env == _svmf_get_current_env ());
1695
1696 _svmm_resuming_java (env);
1697
1698 {
1699 $2 *elements;
1700
1701 if (start < 0 || len < 0 || start + len > (*array)->size)
1702 {
1703 _svmf_error_ArrayIndexOutOfBoundsException (env);
1704 goto end;
1705 }
1706
1707 elements =
1708 ($2 *) (void *) (((char *) *array) +
1709 _svmf_aligned_size_t (sizeof (_svmt_array_instance)));
1710
1711 memcpy (buf, &elements[start], len * sizeof ($2));
1712 }
1713
1714 end:
1715 _svmm_stopping_java (env);
1716 }
1717
1718 m4svm_define_end v = ":])";
1719
1720 /* m4svm_GetArrayRegion(Byte, jbyte) */
1721 /* m4svm_GetArrayRegion(Short, jshort) */
1722 /* m4svm_GetArrayRegion(Char, jchar) */
1723 /* m4svm_GetArrayRegion(Int, jint) */
1724 /* m4svm_GetArrayRegion(Long, jlong) */
1725 /* m4svm_GetArrayRegion(Float, jfloat) */
1726 /* m4svm_GetArrayRegion(Double, jdouble) */
1727
1728 /* m4_undefine([:m4svm_GetArrayRegion:]) */
1729
1730 /*
1731 ----------------------------------------------------------------------
1732 m4svm_SetArrayRegion
1733 ----------------------------------------------------------------------
1734 */
1735
1736 m4svm_define_begin v = ":], [:m4svm_SetArrayRegion:])";
1737
1738 /*
1739 -----------------------------------m4_dnl
1740 -----------------------------------
1741 Set$1ArrayRegion
1742 -----------------------------------m4_dnl
1743 -----------------------------------
1744 */
1745
1746 JNIEXPORT svm_static void JNICALL
Set$1ArrayRegion(JNIEnv * _env,$2Array array,jsize start,jsize len,$2 * buf)1747 Set$1ArrayRegion (JNIEnv *_env, $2Array array, jsize start, jsize len,
1748 $2 * buf)
1749 {
1750 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1751
1752 assert (env == _svmf_get_current_env ());
1753
1754 _svmm_resuming_java (env);
1755
1756 {
1757 $2 *elements;
1758
1759 if (start < 0 || len < 0 || start + len > (*array)->size)
1760 {
1761 _svmf_error_ArrayIndexOutOfBoundsException (env);
1762 goto end;
1763 }
1764
1765 elements =
1766 ($2 *) (void *) (((char *) *array) +
1767 _svmf_aligned_size_t (sizeof (_svmt_array_instance)));
1768
1769 memcpy (&elements[start], buf, len * sizeof ($2));
1770 }
1771
1772 end:
1773 _svmm_stopping_java (env);
1774 }
1775
1776 m4svm_define_end v = ":])";
1777
1778 /* m4svm_SetArrayRegion(Byte, jbyte) */
1779 /* m4svm_SetArrayRegion(Short, jshort) */
1780 /* m4svm_SetArrayRegion(Char, jchar) */
1781 /* m4svm_SetArrayRegion(Int, jint) */
1782 /* m4svm_SetArrayRegion(Long, jlong) */
1783 /* m4svm_SetArrayRegion(Float, jfloat) */
1784 /* m4svm_SetArrayRegion(Double, jdouble) */
1785
1786 /* m4_undefine([:m4svm_SetArrayRegion:]) */
1787
1788 /*
1789 ----------------------------------------------------------------------
1790 m4svm_GetArrayElements
1791 ----------------------------------------------------------------------
1792 */
1793
1794 m4svm_define_begin v = ":], [:m4svm_GetArrayElements:])";
1795
1796 /*
1797 -----------------------------------m4_dnl
1798 -----------------------------------
1799 Get$1ArrayElements
1800 -----------------------------------m4_dnl
1801 -----------------------------------
1802 */
1803
1804 JNIEXPORT svm_static $2 * JNICALL
Get$1ArrayElements(JNIEnv * _env,$2Array array,jboolean * isCopy)1805 Get$1ArrayElements (JNIEnv *_env, $2Array array, jboolean *isCopy)
1806 {
1807 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1808 $2 *result = NULL;
1809
1810 assert (env == _svmf_get_current_env ());
1811
1812 _svmm_resuming_java (env);
1813
1814 assert (array != NULL);
1815 assert ((*array)->vtable->type->is_array == JNI_TRUE);
1816
1817 {
1818 jint size = (*array)->size;
1819
1820 if (size == 0)
1821 {
1822 if (isCopy != NULL)
1823 {
1824 *isCopy = JNI_FALSE;
1825 }
1826
1827 /* The JNI specification says it shouldn't be NULL if no
1828 exception is thrown! Ugly. I think the JNI spec should be
1829 fixed. */
1830 result = ($2 *) 1; /* assuming NULL isn't defined as 1
1831 (unlikely, but allowed by ISO C...) */
1832 goto end;
1833 }
1834
1835 result = _svmf_malloc (size * sizeof ($2));
1836
1837 if (result == NULL)
1838 {
1839 _svmf_error_OutOfMemoryError (env);
1840 goto end;
1841 }
1842
1843 if (isCopy != NULL)
1844 {
1845 *isCopy = JNI_TRUE;
1846 }
1847
1848 memcpy (result,
1849 (((char *) *array) +
1850 _svmf_aligned_size_t (sizeof (_svmt_array_instance))),
1851 size * sizeof ($2));
1852 }
1853
1854 end:
1855 _svmm_stopping_java (env);
1856
1857 return result;
1858 }
1859
1860 m4svm_define_end v = ":])";
1861
1862 /* m4svm_GetArrayElements(Byte, jbyte) */
1863 /* m4svm_GetArrayElements(Short, jshort) */
1864 /* m4svm_GetArrayElements(Char, jchar) */
1865 /* m4svm_GetArrayElements(Int, jint) */
1866 /* m4svm_GetArrayElements(Long, jlong) */
1867 /* m4svm_GetArrayElements(Float, jfloat) */
1868 /* m4svm_GetArrayElements(Double, jdouble) */
1869
1870 /* m4_undefine([:m4svm_GetArrayElements:]) */
1871
1872 /*
1873 ----------------------------------------------------------------------
1874 m4svm_ReleaseArrayElements
1875 ----------------------------------------------------------------------
1876 */
1877
1878 m4svm_define_begin v = ":], [:m4svm_ReleaseArrayElements:])";
1879
1880 /*
1881 -----------------------------------m4_dnl
1882 -----------------------------------
1883 Release$1ArrayElements
1884 -----------------------------------m4_dnl
1885 -----------------------------------
1886 */
1887
1888 JNIEXPORT svm_static void JNICALL
Release$1ArrayElements(JNIEnv * _env,$2Array array,$2 * elems,jint mode)1889 Release$1ArrayElements (JNIEnv *_env, $2Array array, $2 * elems, jint mode)
1890 {
1891 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1892
1893 assert (env == _svmf_get_current_env ());
1894
1895 _svmm_resuming_java (env);
1896
1897 {
1898 jint size = (*array)->size;
1899
1900 if (size == 0)
1901 {
1902 goto end;
1903 }
1904
1905 switch (mode)
1906 {
1907 case 0:
1908 {
1909 memcpy ((((char *) *array) +
1910 _svmf_aligned_size_t (sizeof (_svmt_array_instance))),
1911 elems, size * sizeof ($2));
1912 _svmf_free (elems);
1913 goto end;
1914 }
1915 break;
1916
1917 case JNI_COMMIT:
1918 {
1919 memcpy ((((char *) *array) +
1920 _svmf_aligned_size_t (sizeof (_svmt_array_instance))),
1921 elems, size * sizeof ($2));
1922 goto end;
1923 }
1924 break;
1925
1926 case JNI_ABORT:
1927 {
1928 _svmf_free (elems);
1929 goto end;
1930 }
1931 break;
1932
1933 default:
1934 {
1935 _svmf_jni_fatal_error
1936 ("invalid mode in Release$1ArrayElements call");
1937 }
1938 break;
1939 }
1940 }
1941
1942 end:
1943 _svmm_stopping_java (env);
1944 }
1945
1946 m4svm_define_end v = ":])";
1947
1948 /* m4svm_ReleaseArrayElements(Byte, jbyte) */
1949 /* m4svm_ReleaseArrayElements(Short, jshort) */
1950 /* m4svm_ReleaseArrayElements(Char, jchar) */
1951 /* m4svm_ReleaseArrayElements(Int, jint) */
1952 /* m4svm_ReleaseArrayElements(Long, jlong) */
1953 /* m4svm_ReleaseArrayElements(Float, jfloat) */
1954 /* m4svm_ReleaseArrayElements(Double, jdouble) */
1955
1956 /* m4_undefine([:m4svm_ReleaseArrayElements:]) */
1957
1958 /* m4svm_on(0)m4_dnl */
1959
1960 /*
1961 ----------------------------------------------------------------------
1962 GetObjectField
1963 ----------------------------------------------------------------------
1964 */
1965
1966 JNIEXPORT svm_static jobject JNICALL
GetObjectField(JNIEnv * _env,jobject obj,jfieldID fieldID)1967 GetObjectField (JNIEnv *_env, jobject obj, jfieldID fieldID)
1968 {
1969 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
1970 _svmt_field_info *field = fieldID;
1971 jobject value = NULL;
1972
1973 assert (env == _svmf_get_current_env ());
1974
1975 _svmm_resuming_java (env);
1976
1977 {
1978 size_t offset = field->data.instance_field.offset;
1979 _svmt_object_instance *instance;
1980
1981 instance = _svmf_get_REFERENCE_field (*obj, offset);
1982 if (instance != NULL)
1983 {
1984 value = _svmf_get_jni_frame_native_local (env);
1985 *value = instance;
1986 }
1987 }
1988
1989 _svmm_stopping_java (env);
1990
1991 return value;
1992 }
1993
1994 /*
1995 ----------------------------------------------------------------------
1996 SetObjectField
1997 ----------------------------------------------------------------------
1998 */
1999
2000 JNIEXPORT svm_static void JNICALL
SetObjectField(JNIEnv * _env,jobject obj,jfieldID fieldID,jobject value)2001 SetObjectField (JNIEnv *_env, jobject obj, jfieldID fieldID, jobject value)
2002 {
2003 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2004 _svmt_field_info *field = fieldID;
2005
2006 assert (env == _svmf_get_current_env ());
2007
2008 _svmm_resuming_java (env);
2009
2010 {
2011 size_t offset = field->data.instance_field.offset;
2012
2013 _svmf_put_REFERENCE_field (env, *obj, offset,
2014 (value == NULL) ? NULL : *value);
2015 }
2016
2017 _svmm_stopping_java (env);
2018 }
2019
2020 /*
2021 ----------------------------------------------------------------------
2022 GetStaticObjectField
2023 ----------------------------------------------------------------------
2024 */
2025
2026 JNIEXPORT svm_static jobject JNICALL
GetStaticObjectField(JNIEnv * _env,jclass cls SVM_UNUSED,jfieldID fieldID)2027 GetStaticObjectField (JNIEnv *_env, jclass cls SVM_UNUSED, jfieldID fieldID)
2028 {
2029 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2030 _svmt_field_info *field = fieldID;
2031 jobject value = NULL;
2032
2033 assert (env == _svmf_get_current_env ());
2034
2035 _svmm_resuming_java (env);
2036
2037 {
2038 _svmt_object_instance *instance;
2039
2040 instance = *(field->data.class_field.value.l);
2041 if (instance != NULL)
2042 {
2043 value = _svmf_get_jni_frame_native_local (env);
2044 *value = instance;
2045 }
2046 }
2047
2048 _svmm_stopping_java (env);
2049
2050 return value;
2051 }
2052
2053 /*
2054 ----------------------------------------------------------------------
2055 SetStaticObjectField
2056 ----------------------------------------------------------------------
2057 */
2058
2059 JNIEXPORT svm_static void JNICALL
SetStaticObjectField(JNIEnv * _env,jclass cls SVM_UNUSED,jfieldID fieldID,jobject value)2060 SetStaticObjectField (JNIEnv *_env, jclass cls SVM_UNUSED, jfieldID fieldID,
2061 jobject value)
2062 {
2063 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2064 _svmt_field_info *field = fieldID;
2065
2066 assert (env == _svmf_get_current_env ());
2067
2068 _svmm_resuming_java (env);
2069
2070 *(field->data.class_field.value.l) = (value == NULL) ? NULL : *value;
2071
2072 _svmm_stopping_java (env);
2073 }
2074
2075 /*
2076 ----------------------------------------------------------------------
2077 GetFieldID
2078 ----------------------------------------------------------------------
2079 */
2080
2081 JNIEXPORT svm_static jfieldID JNICALL
GetFieldID(JNIEnv * _env,jclass cls,const char * name,const char * sig)2082 GetFieldID (JNIEnv *_env, jclass cls, const char *name, const char *sig)
2083 {
2084 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2085 _svmt_field_info *field = NULL;
2086
2087 assert (env == _svmf_get_current_env ());
2088
2089 _svmm_resuming_java (env);
2090
2091 {
2092 _svmt_JavaVM *vm = env->vm;
2093 _svmt_type_info *type = _svmf_unwrap_class_instance (env, cls);
2094
2095 if (_svmf_link_type (env, type) != JNI_OK)
2096 {
2097 goto end;
2098 }
2099
2100 if (!type->is_array)
2101 {
2102 if (_svmf_class_initialization (env, _svmf_cast_class (type)) !=
2103 JNI_OK)
2104 {
2105 _svmf_error_ExceptionInInitializerError (env);
2106 goto end;
2107 }
2108 }
2109
2110 if (type->is_array)
2111 {
2112 field =
2113 _svmf_resolve_field (vm->class_loading.boot_loader.classes.
2114 jlobject, name, sig);
2115 }
2116 else
2117 {
2118 field = _svmf_resolve_field (_svmf_cast_class (type), name, sig);
2119 }
2120
2121 if (field == NULL
2122 || _svmf_is_set_flag (field->access_flags, SVM_ACC_STATIC))
2123 {
2124 field = NULL;
2125 _svmf_error_NoSuchFieldError (env);
2126 goto end;
2127 }
2128 }
2129
2130 end:
2131 _svmm_stopping_java (env);
2132
2133 return field;
2134 }
2135
2136 /*
2137 ----------------------------------------------------------------------
2138 GetStaticFieldID
2139 ----------------------------------------------------------------------
2140 */
2141
2142 JNIEXPORT svm_static jfieldID JNICALL
GetStaticFieldID(JNIEnv * _env,jclass cls,const char * name,const char * sig)2143 GetStaticFieldID (JNIEnv *_env, jclass cls, const char *name, const char *sig)
2144 {
2145 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2146 _svmt_field_info *field = NULL;
2147
2148 assert (env == _svmf_get_current_env ());
2149
2150 _svmm_resuming_java (env);
2151
2152 {
2153 _svmt_JavaVM *vm = env->vm;
2154 _svmt_type_info *type = _svmf_unwrap_class_instance (env, cls);
2155
2156 if (_svmf_link_type (env, type) != JNI_OK)
2157 {
2158 goto end;
2159 }
2160
2161 if (!type->is_array)
2162 {
2163 if (_svmf_class_initialization (env, _svmf_cast_class (type)) !=
2164 JNI_OK)
2165 {
2166 _svmf_error_ExceptionInInitializerError (env);
2167 goto end;
2168 }
2169 }
2170
2171 if (type->is_array)
2172 {
2173 field =
2174 _svmf_resolve_field (vm->class_loading.boot_loader.classes.
2175 jlobject, name, sig);
2176 }
2177 else
2178 {
2179 field = _svmf_resolve_field (_svmf_cast_class (type), name, sig);
2180 }
2181
2182 if (field == NULL
2183 || !_svmf_is_set_flag (field->access_flags, SVM_ACC_STATIC))
2184 {
2185 field = NULL;
2186 _svmf_error_NoSuchFieldError (env);
2187 goto end;
2188 }
2189 }
2190
2191 end:
2192 _svmm_stopping_java (env);
2193
2194 return field;
2195 }
2196
2197 /*
2198 ----------------------------------------------------------------------
2199 DeleteLocalRef
2200 ----------------------------------------------------------------------
2201 */
2202
2203 JNIEXPORT svm_static void JNICALL
DeleteLocalRef(JNIEnv * _env,jobject localRef)2204 DeleteLocalRef (JNIEnv *_env, jobject localRef)
2205 {
2206 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2207
2208 assert (env == _svmf_get_current_env ());
2209
2210 _svmm_resuming_java (env);
2211
2212 if (localRef != NULL)
2213 {
2214 _svmt_stack_frame *frame = env->stack.current_frame;
2215 _svmt_stack_native_reference *lrefs =
2216 (_svmt_stack_native_reference *) (void *) (((char *) frame) +
2217 frame->end_offset);
2218 jint lrefs_count = lrefs[-1].jint;
2219 size_t lrefs_size = lrefs[-2].size_t;
2220 jint i;
2221
2222 lrefs =
2223 (_svmt_stack_native_reference *) (void *) (((char *) lrefs) -
2224 lrefs_size);
2225
2226 for (i = 0; i < lrefs_count; i++)
2227 {
2228 if (lrefs[i].jobject == localRef)
2229 {
2230 *(lrefs[i].jobject) = NULL;
2231 break;
2232 }
2233 }
2234 }
2235
2236 _svmm_stopping_java (env);
2237 }
2238
2239
2240 /*
2241 ----------------------------------------------------------------------
2242 GetObjectClass
2243 ----------------------------------------------------------------------
2244 */
2245
2246 JNIEXPORT svm_static jclass JNICALL
GetObjectClass(JNIEnv * _env,jobject obj)2247 GetObjectClass (JNIEnv *_env, jobject obj)
2248 {
2249 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2250 jclass class = NULL;
2251
2252 assert (env == _svmf_get_current_env ());
2253
2254 _svmm_resuming_java (env);
2255
2256 {
2257 class = _svmf_get_jni_frame_native_local (env);
2258 *class = *((*obj)->vtable->type->class_instance);
2259 }
2260
2261 _svmm_stopping_java (env);
2262
2263 return class;
2264 }
2265
2266 /*
2267 ----------------------------------------------------------------------
2268 ThrowNew
2269 ----------------------------------------------------------------------
2270 */
2271
2272 JNIEXPORT svm_static jint JNICALL
ThrowNew(JNIEnv * _env,jclass cls,const char * message)2273 ThrowNew (JNIEnv *_env, jclass cls, const char *message)
2274 {
2275 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2276 jint result = JNI_ERR;
2277
2278 assert (env == _svmf_get_current_env ());
2279
2280 _svmm_resuming_java (env);
2281
2282 {
2283 _svmt_class_info *class =
2284 _svmf_cast_class (_svmf_unwrap_class_instance (env, cls));
2285 _svmt_method_info *method;
2286 jobject throwable;
2287 jstring msg;
2288
2289 if (_svmf_link_class (env, class) != JNI_OK)
2290 {
2291 goto end;
2292 }
2293
2294 if (_svmf_class_initialization (env, class) != JNI_OK)
2295 {
2296 goto end;
2297 }
2298
2299 throwable = _svmf_get_jni_frame_native_local (env);
2300 if (_svmm_new_object_instance (env, class, *throwable) != JNI_OK)
2301 {
2302 goto end;
2303 }
2304
2305 msg = _svmf_get_jni_frame_native_local (env);
2306 if (_svmf_get_string (env, message, msg) != JNI_OK)
2307 {
2308 goto end;
2309 }
2310
2311 method = _svmf_resolve_method (class, "<init>", "(Ljava/lang/String;)V");
2312
2313 if (method == NULL)
2314 {
2315 _svmf_error_NoSuchMethodError (env);
2316 goto end;
2317 }
2318
2319 if (_svmm_invoke_specific_nonvirtual_throwinit
2320 (env, method, throwable, msg) != JNI_OK)
2321 {
2322 goto end;
2323 }
2324
2325 *(env->throwable) = *throwable;
2326
2327 result = JNI_OK;
2328 }
2329
2330 end:
2331 _svmm_stopping_java (env);
2332
2333 return result;
2334 }
2335
2336 /*
2337 ----------------------------------------------------------------------
2338 NewGlobalRef
2339 ----------------------------------------------------------------------
2340 */
2341
2342 JNIEXPORT svm_static jobject JNICALL
NewGlobalRef(JNIEnv * _env,jobject obj)2343 NewGlobalRef (JNIEnv *_env, jobject obj)
2344 {
2345 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2346 jobject result = NULL;
2347
2348 assert (env == _svmf_get_current_env ());
2349
2350 _svmm_resuming_java (env);
2351
2352 if (obj == NULL || *obj == NULL)
2353 {
2354 goto end;
2355 }
2356
2357 if (_svmm_new_native_global (env, result) != JNI_OK)
2358 {
2359 *(env->throwable) = NULL;
2360 goto end;
2361 }
2362
2363 *result = *obj;
2364
2365 end:
2366 _svmm_stopping_java (env);
2367
2368 return result;
2369 }
2370
2371 /*
2372 ----------------------------------------------------------------------
2373 GetStringUTFLength
2374 ----------------------------------------------------------------------
2375 */
2376
2377 JNIEXPORT svm_static jsize JNICALL
GetStringUTFLength(JNIEnv * _env,jstring string)2378 GetStringUTFLength (JNIEnv *_env, jstring string)
2379 {
2380 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2381 jint result = 0; /* init just to keep compiler happy */
2382
2383 assert (env == _svmf_get_current_env ());
2384
2385 _svmm_resuming_java (env);
2386
2387 _svmm_invoke_static_stringcreator_getutflength (env, string, result);
2388
2389 _svmm_stopping_java (env);
2390
2391 return result;
2392 }
2393
2394 /*
2395 ----------------------------------------------------------------------
2396 GetStringUTFChars
2397 ----------------------------------------------------------------------
2398 */
2399
2400 JNIEXPORT svm_static const char *JNICALL
GetStringUTFChars(JNIEnv * _env,jstring string,jboolean * isCopy)2401 GetStringUTFChars (JNIEnv *_env, jstring string, jboolean *isCopy)
2402 {
2403 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2404 char *result = NULL;;
2405
2406 assert (env == _svmf_get_current_env ());
2407
2408 _svmm_resuming_java (env);
2409
2410 {
2411 char *chars;
2412
2413 if (_svmm_galloc_utf_chars (env, string, chars) != JNI_OK)
2414 {
2415 goto end;
2416 }
2417
2418 if (isCopy != NULL)
2419 {
2420 *isCopy = JNI_TRUE;
2421 }
2422
2423 result = chars;
2424 }
2425
2426 end:
2427 _svmm_stopping_java (env);
2428
2429 return result;
2430 }
2431
2432 /*
2433 ----------------------------------------------------------------------
2434 ReleaseStringUTFChars
2435 ----------------------------------------------------------------------
2436 */
2437
2438 JNIEXPORT svm_static void JNICALL
ReleaseStringUTFChars(JNIEnv * _env,jstring string SVM_UNUSED,const char * utf)2439 ReleaseStringUTFChars (JNIEnv *_env, jstring string SVM_UNUSED,
2440 const char *utf)
2441 {
2442 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2443
2444 assert (env == _svmf_get_current_env ());
2445
2446 _svmm_resuming_java (env);
2447
2448 {
2449 char *chars = (char *) utf;;
2450
2451 _svmm_gfree_utf_chars (chars);
2452 }
2453
2454 _svmm_stopping_java (env);
2455 }
2456
2457 /*
2458 ----------------------------------------------------------------------
2459 ExceptionCheck
2460 ----------------------------------------------------------------------
2461 */
2462
2463 JNIEXPORT svm_static jboolean JNICALL
ExceptionCheck(JNIEnv * _env)2464 ExceptionCheck (JNIEnv *_env)
2465 {
2466 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2467 jboolean result;
2468
2469 assert (env == _svmf_get_current_env ());
2470
2471 _svmm_resuming_java (env);
2472
2473 result = *(env->throwable) != NULL;
2474
2475 _svmm_stopping_java (env);
2476
2477 return result;
2478 }
2479
2480 /*
2481 ----------------------------------------------------------------------
2482 SetObjectArrayElement
2483 ----------------------------------------------------------------------
2484 */
2485
2486 JNIEXPORT svm_static void JNICALL
SetObjectArrayElement(JNIEnv * _env,jobjectArray array,jsize indx,jobject value)2487 SetObjectArrayElement (JNIEnv *_env, jobjectArray array, jsize indx,
2488 jobject value)
2489 {
2490 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2491
2492 assert (env == _svmf_get_current_env ());
2493
2494 _svmm_resuming_java (env);
2495
2496 {
2497 jint size = (*array)->size;
2498
2499 /* check array bounds */
2500 if (((_svmt_u32) indx) >= (_svmt_u32) size)
2501 {
2502 _svmf_error_ArrayIndexOutOfBoundsException (env);
2503 goto end;
2504 }
2505
2506 if (_svmf_set_reference_array_element_no_exception
2507 (env, *array, indx, (value == NULL) ? NULL : *value) != JNI_OK)
2508 {
2509 _svmf_error_ArrayStoreException (env);
2510 goto end;
2511 }
2512 }
2513
2514 end:
2515 _svmm_stopping_java (env);
2516 }
2517
2518 /*
2519 ----------------------------------------------------------------------
2520 NewStringUTF
2521 ----------------------------------------------------------------------
2522 */
2523
2524 JNIEXPORT svm_static jstring JNICALL
NewStringUTF(JNIEnv * _env,const char * bytes)2525 NewStringUTF (JNIEnv *_env, const char *bytes)
2526 {
2527 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2528 jstring string = NULL;
2529
2530 assert (env == _svmf_get_current_env ());
2531
2532 _svmm_resuming_java (env);
2533
2534 assert (*(env->throwable) == NULL);
2535
2536 {
2537 string = _svmf_get_jni_frame_native_local (env);
2538 if (_svmf_get_string (env, bytes, string) != JNI_OK)
2539 {
2540 string = NULL;
2541 goto end;
2542 }
2543 }
2544
2545 end:
2546 _svmm_stopping_java (env);
2547
2548 return string;
2549 }
2550
2551 /*
2552 ----------------------------------------------------------------------
2553 NewObjectArray
2554 ----------------------------------------------------------------------
2555 */
2556
2557 JNIEXPORT svm_static jarray JNICALL
NewObjectArray(JNIEnv * _env,jsize length,jclass elementClass,jobject initialElement)2558 NewObjectArray (JNIEnv *_env, jsize length, jclass elementClass,
2559 jobject initialElement)
2560 {
2561 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2562 jarray array = NULL;
2563
2564 assert (env == _svmf_get_current_env ());
2565
2566 _svmm_resuming_java (env);
2567
2568 {
2569 _svmt_type_info *type = _svmf_unwrap_class_instance (env, elementClass);
2570 _svmt_array_info *array_type;
2571
2572 if (_svmm_create_array
2573 (env, type->class_loader_info, type->array_type_name,
2574 array_type) != JNI_OK)
2575 {
2576 goto end;
2577 }
2578
2579 if (_svmf_link_array (env, array_type) != JNI_OK)
2580 {
2581 goto end;
2582 }
2583
2584 array = _svmf_get_jni_frame_native_local_array (env);
2585 if (_svmm_new_array_instance (env, array_type, length, *array) != JNI_OK)
2586 {
2587 array = NULL;
2588 goto end;
2589 }
2590
2591 if (initialElement != NULL)
2592 {
2593 _svmt_object_instance *value = *initialElement;
2594 _svmt_object_instance **elements;
2595 jint i;
2596
2597 #if defined (_SABLEVM_BIDIRECTIONAL_OBJECT_LAYOUT)
2598
2599 elements = (_svmt_object_instance **) *array;
2600
2601 #else
2602
2603 elements = (_svmt_object_instance **) (void *)
2604 (((char *) *array) +
2605 _svmf_aligned_size_t (sizeof (_svmt_array_instance)));
2606
2607 #endif
2608
2609 for (i = 0; i < length; i++)
2610 {
2611 #if defined (_SABLEVM_BIDIRECTIONAL_OBJECT_LAYOUT)
2612
2613 elements[(-1) - i] = value;
2614 #if defined (_SABLEVM_GC_WRITE_BARRIER)
2615 _svmf_write_barrier
2616 (env, (_svmt_object_instance **) (void *) &elements[(-1) - i]);
2617 #endif /* _SABLEVM_GC_WRITE_BARRIER */
2618 #else
2619
2620 elements[i] = value;
2621 #if defined (_SABLEVM_GC_WRITE_BARRIER)
2622 _svmf_write_barrier
2623 (env, (_svmt_object_instance **) &elements[i]);
2624 #endif /* _SABLEVM_GC_WRITE_BARRIER */
2625 #endif
2626 }
2627 }
2628 }
2629
2630 end:
2631 _svmm_stopping_java (env);
2632
2633 return array;
2634 }
2635
2636 /*
2637 ----------------------------------------------------------------------
2638 GetMethodID
2639 ----------------------------------------------------------------------
2640 */
2641
2642 JNIEXPORT svm_static jmethodID JNICALL
GetMethodID(JNIEnv * _env,jclass cls,const char * name,const char * sig)2643 GetMethodID (JNIEnv *_env, jclass cls, const char *name, const char *sig)
2644 {
2645 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2646 _svmt_method_info *method = NULL;
2647
2648 assert (env == _svmf_get_current_env ());
2649
2650 _svmm_resuming_java (env);
2651
2652 {
2653 _svmt_JavaVM *vm = env->vm;
2654 _svmt_type_info *type = _svmf_unwrap_class_instance (env, cls);
2655
2656 if (_svmf_link_type (env, type) != JNI_OK)
2657 {
2658 goto end;
2659 }
2660
2661 if (!type->is_array)
2662 {
2663 if (_svmf_class_initialization (env, _svmf_cast_class (type)) !=
2664 JNI_OK)
2665 {
2666 _svmf_error_ExceptionInInitializerError (env);
2667 goto end;
2668 }
2669 }
2670
2671 if (type->is_array)
2672 {
2673 method =
2674 _svmf_resolve_method (vm->class_loading.boot_loader.classes.
2675 jlobject, name, sig);
2676 }
2677 else
2678 {
2679 method = _svmf_resolve_method (_svmf_cast_class (type), name, sig);
2680 }
2681
2682 if (method == NULL
2683 || _svmf_is_set_flag (method->access_flags, SVM_ACC_STATIC))
2684 {
2685 method = NULL;
2686 _svmf_error_NoSuchMethodError (env);
2687 goto end;
2688 }
2689 }
2690
2691 end:
2692 _svmm_stopping_java (env);
2693
2694 return method;
2695 }
2696
2697 /*
2698 ----------------------------------------------------------------------
2699 GetStaticMethodID
2700 ----------------------------------------------------------------------
2701 */
2702
2703 JNIEXPORT svm_static jmethodID JNICALL
GetStaticMethodID(JNIEnv * _env,jclass cls,const char * name,const char * sig)2704 GetStaticMethodID (JNIEnv *_env, jclass cls, const char *name,
2705 const char *sig)
2706 {
2707 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2708 _svmt_method_info *method = NULL;
2709
2710 assert (env == _svmf_get_current_env ());
2711
2712 _svmm_resuming_java (env);
2713
2714 {
2715 _svmt_JavaVM *vm = env->vm;
2716 _svmt_type_info *type = _svmf_unwrap_class_instance (env, cls);
2717
2718 if (_svmf_link_type (env, type) != JNI_OK)
2719 {
2720 goto end;
2721 }
2722
2723 if (!type->is_array)
2724 {
2725 if (_svmf_class_initialization (env, _svmf_cast_class (type)) !=
2726 JNI_OK)
2727 {
2728 _svmf_error_ExceptionInInitializerError (env);
2729 goto end;
2730 }
2731 }
2732
2733 if (type->is_array)
2734 {
2735 method =
2736 _svmf_resolve_method (vm->class_loading.boot_loader.classes.
2737 jlobject, name, sig);
2738 }
2739 else
2740 {
2741 method = _svmf_resolve_method (_svmf_cast_class (type), name, sig);
2742 }
2743
2744 if (method == NULL
2745 || !_svmf_is_set_flag (method->access_flags, SVM_ACC_STATIC))
2746 {
2747 method = NULL;
2748 _svmf_error_NoSuchMethodError (env);
2749 goto end;
2750 }
2751 }
2752
2753 end:
2754 _svmm_stopping_java (env);
2755
2756 return method;
2757 }
2758
2759 /*
2760 ----------------------------------------------------------------------
2761 ExceptionDescribe
2762 ----------------------------------------------------------------------
2763 */
2764
2765 JNIEXPORT svm_static void JNICALL
ExceptionDescribe(JNIEnv * _env)2766 ExceptionDescribe (JNIEnv *_env)
2767 {
2768 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2769
2770 assert (env == _svmf_get_current_env ());
2771
2772 _svmm_resuming_java (env);
2773
2774 {
2775 jthrowable throwable = _svmf_get_jni_frame_native_local (env);
2776 jstring jtext = _svmf_get_jni_frame_native_local (env);
2777 char *ctext = NULL;
2778
2779
2780 *throwable = *(env->throwable);
2781 *(env->throwable) = NULL;
2782
2783 if (_svmm_invoke_static_virtualmachine_exceptiondescribe (env, throwable)
2784 == JNI_OK)
2785 {
2786 goto done;
2787 }
2788
2789 /* There was an exception thrown while trying to print the stack
2790 trace using Java code. So, we now try to convert the whole
2791 exception & stack trace to a string, then print it here */
2792
2793 /* forget the new exception */
2794 *(env->throwable) = NULL;
2795
2796 if (_svmm_invoke_static_virtualmachine_exceptiondescription
2797 (env, throwable, jtext) != JNI_OK)
2798 {
2799 goto try_again;
2800 }
2801
2802 if (_svmm_galloc_utf_chars (env, jtext, ctext) != JNI_OK)
2803 {
2804 goto try_again;
2805 }
2806
2807 _svmf_printf (env, stderr, "%s\n", ctext);
2808
2809 _svmm_gfree_utf_chars (ctext);
2810
2811 goto done;
2812
2813 try_again:
2814 /* There was yet again an exception trying to retrieve a full
2815 stack trace. So, we try to at least provide the exception
2816 toString() info. */
2817
2818 /* forget the new exception */
2819 *(env->throwable) = NULL;
2820
2821 if (_svmm_invoke_static_virtualmachine_exceptiontruncateddescription
2822 (env, throwable, jtext) != JNI_OK)
2823 {
2824 goto try_one_last_time;
2825 }
2826
2827 if (_svmm_galloc_utf_chars (env, jtext, ctext) != JNI_OK)
2828 {
2829 goto try_one_last_time;
2830 }
2831
2832 _svmf_printf (env, stderr, "%s\n", ctext);
2833
2834 _svmm_gfree_utf_chars (ctext);
2835
2836 goto done;
2837
2838 try_one_last_time:
2839 /* We were unable to get any info from Java. Print some minimal
2840 info. */
2841
2842 /* forget the new exception */
2843 *(env->throwable) = NULL;
2844
2845 /* print the old exception class name */
2846 _svmf_printf (env, stderr, "%s\n", (*throwable)->vtable->type->name);
2847
2848 done:
2849 _svmm_release_jni_frame_native_local (throwable);
2850 _svmm_release_jni_frame_native_local (jtext);
2851 }
2852
2853 _svmm_stopping_java (env);
2854 }
2855
2856 /*
2857 ----------------------------------------------------------------------
2858 ExceptionOccurred
2859 ----------------------------------------------------------------------
2860 */
2861
2862 JNIEXPORT svm_static jthrowable JNICALL
ExceptionOccurred(JNIEnv * _env)2863 ExceptionOccurred (JNIEnv *_env)
2864 {
2865 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2866 jthrowable throwable = NULL;
2867
2868 assert (env == _svmf_get_current_env ());
2869
2870 _svmm_resuming_java (env);
2871
2872 if (*(env->throwable) != NULL)
2873 {
2874 throwable = _svmf_get_jni_frame_native_local (env);
2875 *throwable = *(env->throwable);
2876 }
2877
2878 _svmm_stopping_java (env);
2879
2880 return throwable;
2881 }
2882
2883 /*
2884 ----------------------------------------------------------------------
2885 ExceptionClear
2886 ----------------------------------------------------------------------
2887 */
2888
2889 JNIEXPORT svm_static void JNICALL
ExceptionClear(JNIEnv * _env)2890 ExceptionClear (JNIEnv *_env)
2891 {
2892 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2893
2894 assert (env == _svmf_get_current_env ());
2895
2896 _svmm_resuming_java (env);
2897
2898 *(env->throwable) = NULL;
2899
2900 _svmm_stopping_java (env);
2901 }
2902
2903 /*
2904 ----------------------------------------------------------------------
2905 GetVersion
2906 ----------------------------------------------------------------------
2907 */
2908
2909 JNIEXPORT svm_static jint JNICALL
GetVersion(JNIEnv * _env)2910 GetVersion (JNIEnv *_env)
2911 {
2912 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2913
2914 assert (env == _svmf_get_current_env ());
2915
2916 _svmm_resuming_java (env);
2917
2918 _svmm_stopping_java (env);
2919
2920 return JNI_VERSION_1_4;
2921 }
2922
2923 /*
2924 ----------------------------------------------------------------------
2925 FindClass
2926 ----------------------------------------------------------------------
2927 */
2928
2929 JNIEXPORT svm_static jclass JNICALL
FindClass(JNIEnv * _env,const char * name)2930 FindClass (JNIEnv *_env, const char *name)
2931 {
2932 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
2933 jclass class = NULL;
2934
2935 assert (env == _svmf_get_current_env ());
2936
2937 _svmm_resuming_java (env);
2938
2939 {
2940 _svmt_JavaVM *vm = env->vm;
2941 _svmt_stack_frame *frame = env->stack.current_frame;
2942 _svmt_class_loader_info *class_loader_info;
2943
2944
2945 /* get class loader */
2946 if (frame->method == &vm->stack_bottom_method)
2947 {
2948 jarray vmdata = _svmf_get_jni_frame_native_local_array (env);
2949 if (_svmm_invoke_static_virtualmachine_getsystemcl
2950 (env, _svmf_cast_jobject (vmdata)) != JNI_OK)
2951 {
2952 goto end;
2953 }
2954 class_loader_info = _svmf_unwrap_pointer (*vmdata);
2955 _svmm_release_jni_frame_native_local_array (vmdata);
2956 }
2957 else
2958 {
2959 class_loader_info = frame->method->class_info->class_loader_info;
2960 }
2961
2962 /* load, link, and initialize type */
2963 {
2964 _svmt_type_info *type;
2965
2966 if (_svmm_create_type (env, class_loader_info, name, type) != JNI_OK)
2967 {
2968 goto end;
2969 }
2970
2971 if (_svmf_link_type (env, type) != JNI_OK)
2972 {
2973 goto end;
2974 }
2975
2976 if (!(type->is_array))
2977 {
2978 if (_svmf_class_initialization
2979 (env, _svmf_cast_class (type)) != JNI_OK)
2980 {
2981 goto end;
2982 }
2983 }
2984
2985 class = _svmf_get_jni_frame_native_local (env);
2986 *class = *(type->class_instance);
2987 }
2988 }
2989
2990 end:
2991 _svmm_stopping_java (env);
2992
2993 return class;
2994 }
2995
2996 /*
2997 ----------------------------------------------------------------------
2998 GetArrayLength
2999 ----------------------------------------------------------------------
3000 */
3001
3002 JNIEXPORT svm_static jsize JNICALL
GetArrayLength(JNIEnv * _env,jarray array)3003 GetArrayLength (JNIEnv *_env, jarray array)
3004 {
3005 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3006 jint size;
3007
3008 assert (env == _svmf_get_current_env ());
3009
3010 _svmm_resuming_java (env);
3011
3012 size = (*array)->size;
3013
3014 _svmm_stopping_java (env);
3015
3016 return size;
3017 }
3018
3019 /*
3020 ----------------------------------------------------------------------
3021 DefineClass
3022 ----------------------------------------------------------------------
3023 */
3024
3025 JNIEXPORT svm_static jclass JNICALL
DefineClass(JNIEnv * _env,const char * name SVM_UNUSED,jobject loader SVM_UNUSED,const jbyte * buf SVM_UNUSED,jsize bufLen SVM_UNUSED)3026 DefineClass (JNIEnv *_env, const char *name SVM_UNUSED,
3027 jobject loader SVM_UNUSED, const jbyte *buf SVM_UNUSED,
3028 jsize bufLen SVM_UNUSED)
3029 {
3030 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3031
3032 assert (env == _svmf_get_current_env ());
3033
3034 _svmm_resuming_java (env);
3035
3036 _svmm_fatal_error ("todo");
3037
3038 _svmm_stopping_java (env);
3039
3040 return NULL;
3041 }
3042
3043 /*
3044 ----------------------------------------------------------------------
3045 GetSuperclass
3046 ----------------------------------------------------------------------
3047 */
3048
3049 JNIEXPORT svm_static jclass JNICALL
GetSuperclass(JNIEnv * _env,jclass cls)3050 GetSuperclass (JNIEnv *_env, jclass cls)
3051 {
3052 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3053 jclass super = NULL;
3054
3055 assert (env == _svmf_get_current_env ());
3056
3057 _svmm_resuming_java (env);
3058
3059 /*
3060 * Note:
3061 * implementation very similar to Java_java_lang_VMClass_getSuperclass
3062 */
3063 {
3064 _svmt_JavaVM *vm = env->vm;
3065 /* Note: Will not work for Class of primitive types */
3066 _svmt_type_info *type = _svmf_unwrap_class_instance (env, cls);
3067
3068 if (type->is_array)
3069 {
3070 super = _svmf_get_jni_frame_native_local (env);
3071 *super =
3072 *(vm->class_loading.boot_loader.classes.jlobject->class_instance);
3073 goto end;
3074 }
3075 if (_svmf_is_set_flag (type->access_flags, SVM_ACC_INTERFACE))
3076 {
3077 goto end;
3078 }
3079
3080 /* has super type */
3081 super = _svmf_get_jni_frame_native_local (env);
3082 {
3083 _svmt_CONSTANT_Class_info *super_class;
3084 super_class = *(_svmf_cast_class (type)->super_class);
3085 if (super_class == NULL)
3086 {
3087 super = NULL;
3088 goto end;
3089 }
3090 else
3091 {
3092 *super = *(super_class->type->class_instance);
3093 }
3094 }
3095
3096 }
3097 end:
3098 _svmm_stopping_java (env);
3099
3100 return super;
3101 }
3102
3103 /*
3104 ----------------------------------------------------------------------
3105 IsAssignableFrom
3106 ----------------------------------------------------------------------
3107 */
3108
3109 JNIEXPORT svm_static jboolean JNICALL
IsAssignableFrom(JNIEnv * _env,jclass cls1,jclass cls2)3110 IsAssignableFrom (JNIEnv *_env, jclass cls1, jclass cls2)
3111 {
3112 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3113 jboolean is_assignable;
3114
3115 assert (env == _svmf_get_current_env ());
3116
3117 _svmm_resuming_java (env);
3118
3119 {
3120 /* Note: Will not work for Class of primitive types */
3121 _svmt_type_info *from = _svmf_unwrap_class_instance (env, cls1);
3122 _svmt_type_info *to = _svmf_unwrap_class_instance (env, cls2);
3123
3124 is_assignable = _svmf_is_assignable_from (env, from, to);
3125 }
3126
3127 _svmm_stopping_java (env);
3128
3129 return is_assignable;
3130 }
3131
3132 /*
3133 ----------------------------------------------------------------------
3134 Throw
3135 ----------------------------------------------------------------------
3136 */
3137
3138 JNIEXPORT svm_static jint JNICALL
Throw(JNIEnv * _env,jthrowable obj)3139 Throw (JNIEnv *_env, jthrowable obj)
3140 {
3141 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3142
3143 assert (env == _svmf_get_current_env ());
3144
3145 _svmm_resuming_java (env);
3146
3147 {
3148 *(env->throwable) = *obj;
3149 }
3150
3151 _svmm_stopping_java (env);
3152
3153 return JNI_OK;
3154 }
3155
3156 /*
3157 ----------------------------------------------------------------------
3158 FatalError
3159 ----------------------------------------------------------------------
3160 */
3161
3162 JNIEXPORT svm_static void JNICALL
FatalError(JNIEnv * _env,const char * msg)3163 FatalError (JNIEnv *_env, const char *msg)
3164 {
3165 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3166
3167 assert (env == _svmf_get_current_env ());
3168
3169 _svmm_resuming_java (env);
3170
3171 {
3172 _svmm_fatal_error (msg);
3173 }
3174
3175 _svmm_stopping_java (env);
3176 }
3177
3178 /*
3179 ----------------------------------------------------------------------
3180 DeleteGlobalRef
3181 ----------------------------------------------------------------------
3182 */
3183
3184 JNIEXPORT svm_static void JNICALL
DeleteGlobalRef(JNIEnv * _env,jobject globalRef)3185 DeleteGlobalRef (JNIEnv *_env, jobject globalRef)
3186 {
3187 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3188
3189 assert (env == _svmf_get_current_env ());
3190
3191 _svmm_resuming_java (env);
3192
3193 {
3194 _svmm_free_native_global (env, globalRef);
3195 }
3196
3197 _svmm_stopping_java (env);
3198 }
3199
3200 /*
3201 ----------------------------------------------------------------------
3202 IsSameObject
3203 ----------------------------------------------------------------------
3204 */
3205
3206 JNIEXPORT svm_static jboolean JNICALL
IsSameObject(JNIEnv * _env,jobject ref1,jobject ref2)3207 IsSameObject (JNIEnv *_env, jobject ref1, jobject ref2)
3208 {
3209 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3210 jboolean result = JNI_FALSE;
3211
3212 assert (env == _svmf_get_current_env ());
3213
3214 _svmm_resuming_java (env);
3215
3216 {
3217 if (ref1 == NULL)
3218 {
3219 if (ref2 == NULL)
3220 {
3221 result = JNI_TRUE;
3222 }
3223 else
3224 {
3225 result = JNI_FALSE;
3226 }
3227 }
3228 else
3229 {
3230 result = (*ref1 == *ref2) ? JNI_TRUE : JNI_FALSE;
3231 }
3232 }
3233
3234 _svmm_stopping_java (env);
3235
3236 return result;
3237 }
3238
3239 /*
3240 ----------------------------------------------------------------------
3241 AllocObject
3242 ----------------------------------------------------------------------
3243 */
3244
3245 JNIEXPORT svm_static jobject JNICALL
AllocObject(JNIEnv * _env,jclass cls)3246 AllocObject (JNIEnv *_env, jclass cls)
3247 {
3248 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3249 jobject result = NULL;
3250
3251 assert (env == _svmf_get_current_env ());
3252
3253 _svmm_resuming_java (env);
3254
3255 {
3256 _svmt_class_info *class =
3257 _svmf_cast_class (_svmf_unwrap_class_instance (env, cls));
3258 jobject instance;
3259
3260 /* allocate new instance */
3261 instance = _svmf_get_jni_frame_native_local (env);
3262 if (_svmm_new_object_instance (env, class, *instance) != JNI_OK)
3263 {
3264 goto end;
3265 }
3266
3267 /* if no exception was raised, return new instance */
3268 if (*(env->throwable) == NULL)
3269 {
3270 result = instance;
3271 }
3272 }
3273
3274 end:
3275 _svmm_stopping_java (env);
3276
3277 return result;
3278 }
3279
3280 /*
3281 ----------------------------------------------------------------------
3282 NewObject
3283 ----------------------------------------------------------------------
3284 */
3285
3286 JNIEXPORT svm_static jobject JNICALL
NewObject(JNIEnv * _env,jclass cls,jmethodID methodID,...)3287 NewObject (JNIEnv *_env, jclass cls, jmethodID methodID, ...)
3288 {
3289 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3290 jobject result = NULL;
3291
3292 assert (env == _svmf_get_current_env ());
3293
3294 _svmm_resuming_java (env);
3295
3296 {
3297 _svmt_class_info *class =
3298 _svmf_cast_class (_svmf_unwrap_class_instance (env, cls));
3299 jobject instance;
3300
3301 /* allocate new instance */
3302 instance = _svmf_get_jni_frame_native_local (env);
3303 if (_svmm_new_object_instance (env, class, *instance) != JNI_OK)
3304 {
3305 goto end;
3306 }
3307
3308 /* call constructor */
3309 {
3310 va_list args;
3311
3312 va_start (args, methodID);
3313
3314 _svmf_internal_CallNonvirtualVoidMethodV (env, instance, cls, methodID,
3315 args);
3316
3317 va_end (args);
3318 }
3319
3320 /* if no exception was raised, return new instance */
3321 if (*(env->throwable) == NULL)
3322 {
3323 result = instance;
3324 }
3325 }
3326
3327 end:
3328 _svmm_stopping_java (env);
3329
3330 return result;
3331 }
3332
3333 /*
3334 ----------------------------------------------------------------------
3335 NewObjectV
3336 ----------------------------------------------------------------------
3337 */
3338
3339 JNIEXPORT svm_static jobject JNICALL
NewObjectV(JNIEnv * _env,jclass cls,jmethodID methodID,va_list args)3340 NewObjectV (JNIEnv *_env, jclass cls, jmethodID methodID, va_list args)
3341 {
3342 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3343 jobject result = NULL;
3344
3345 assert (env == _svmf_get_current_env ());
3346
3347 _svmm_resuming_java (env);
3348
3349 {
3350 _svmt_class_info *class =
3351 _svmf_cast_class (_svmf_unwrap_class_instance (env, cls));
3352 jobject instance;
3353
3354 /* allocate new instance */
3355 instance = _svmf_get_jni_frame_native_local (env);
3356 if (_svmm_new_object_instance (env, class, *instance) != JNI_OK)
3357 {
3358 goto end;
3359 }
3360
3361 /* call constructor */
3362 _svmf_internal_CallNonvirtualVoidMethodV (env, instance, cls, methodID,
3363 args);
3364
3365 /* if no exception was raised, return new instance */
3366 if (*(env->throwable) == NULL)
3367 {
3368 result = instance;
3369 }
3370 }
3371
3372 end:
3373 _svmm_stopping_java (env);
3374
3375 return result;
3376 }
3377
3378 /*
3379 ----------------------------------------------------------------------
3380 NewObjectA
3381 ----------------------------------------------------------------------
3382 */
3383
3384 JNIEXPORT svm_static jobject JNICALL
NewObjectA(JNIEnv * _env,jclass cls,jmethodID methodID,jvalue * args)3385 NewObjectA (JNIEnv *_env, jclass cls, jmethodID methodID, jvalue *args)
3386 {
3387 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3388 jobject result = NULL;
3389
3390 assert (env == _svmf_get_current_env ());
3391
3392 _svmm_resuming_java (env);
3393
3394 {
3395 _svmt_class_info *class =
3396 _svmf_cast_class (_svmf_unwrap_class_instance (env, cls));
3397 jobject instance;
3398
3399 /* allocate new instance */
3400 instance = _svmf_get_jni_frame_native_local (env);
3401 if (_svmm_new_object_instance (env, class, *instance) != JNI_OK)
3402 {
3403 goto end;
3404 }
3405
3406 /* call constructor */
3407 _svmf_internal_CallNonvirtualVoidMethodA (env, instance, cls, methodID,
3408 args);
3409
3410 /* if no exception was raised, return new instance */
3411 if (*(env->throwable) == NULL)
3412 {
3413 result = instance;
3414 }
3415 }
3416
3417 end:
3418 _svmm_stopping_java (env);
3419
3420 return result;
3421 }
3422
3423 /*
3424 ----------------------------------------------------------------------
3425 IsInstanceOf
3426 ----------------------------------------------------------------------
3427 */
3428
3429 JNIEXPORT svm_static jboolean JNICALL
IsInstanceOf(JNIEnv * _env,jobject obj,jclass cls)3430 IsInstanceOf (JNIEnv *_env, jobject obj, jclass cls)
3431 {
3432 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3433 jboolean result;
3434
3435 assert (env == _svmf_get_current_env ());
3436
3437 _svmm_resuming_java (env);
3438
3439 {
3440 if (obj == NULL)
3441 {
3442 result = JNI_TRUE;
3443 }
3444 else
3445 {
3446 /* Note: Will not work for Class of primitive types */
3447 _svmt_type_info *T = _svmf_unwrap_class_instance (env, cls);
3448 _svmt_type_info *S = (*obj)->vtable->type;
3449
3450 result = _svmf_is_assignable_from (env, S, T);
3451 }
3452 }
3453
3454 _svmm_stopping_java (env);
3455
3456 return result;
3457 }
3458
3459 /*
3460 ----------------------------------------------------------------------
3461 NewString
3462 ----------------------------------------------------------------------
3463 */
3464
3465 JNIEXPORT svm_static jstring JNICALL
NewString(JNIEnv * _env,const jchar * unicodeChars,jsize len)3466 NewString (JNIEnv *_env, const jchar *unicodeChars, jsize len)
3467 {
3468 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3469 _svmt_JavaVM *vm = env->vm;
3470 jstring string = NULL;
3471
3472 assert (env == _svmf_get_current_env ());
3473
3474 _svmm_resuming_java (env);
3475
3476 {
3477 jcharArray data = NULL;
3478
3479 if (_svmm_new_native_local_array (env, data) != JNI_OK)
3480 {
3481 goto end;
3482 }
3483
3484 if (_svmm_new_array_instance
3485 (env, vm->class_loading.boot_loader.classes.char_array, len,
3486 *data) != JNI_OK)
3487 {
3488 _svmm_free_native_local_array (env, data);
3489 goto end;
3490 }
3491
3492 /* put the string characters into the array */
3493 if (len > 0)
3494 {
3495 memcpy (((char *) *data) +
3496 _svmf_aligned_size_t (sizeof (_svmt_array_instance)),
3497 unicodeChars, len * sizeof (jchar));
3498 }
3499
3500 string = _svmf_get_jni_frame_native_local (env);
3501
3502 if (_svmm_invoke_static_stringcreator_createstringfromchars
3503 (env, _svmf_cast_jobject (data), string) == JNI_ERR)
3504 {
3505 _svmm_free_native_local_array (env, data);
3506 _svmm_release_jni_frame_native_local (string);
3507 goto end;
3508 }
3509
3510 _svmm_free_native_local_array (env, data);
3511 }
3512
3513 end:
3514 _svmm_stopping_java (env);
3515
3516 return string;
3517 }
3518
3519 /*
3520 ----------------------------------------------------------------------
3521 GetStringLength
3522 ----------------------------------------------------------------------
3523 */
3524
3525 JNIEXPORT svm_static jsize JNICALL
GetStringLength(JNIEnv * _env,jstring string)3526 GetStringLength (JNIEnv *_env, jstring string)
3527 {
3528 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3529 jint result = -1;
3530
3531 assert (env == _svmf_get_current_env ());
3532
3533 _svmm_resuming_java (env);
3534
3535 if (_svmm_invoke_static_stringcreator_getlength (env, string, result) !=
3536 JNI_OK)
3537 {
3538 goto end;
3539 }
3540
3541 end:
3542 _svmm_stopping_java (env);
3543
3544 return result;
3545 }
3546
3547 /*
3548 ----------------------------------------------------------------------
3549 GetStringChars
3550 ----------------------------------------------------------------------
3551 */
3552
3553 JNIEXPORT svm_static const jchar *JNICALL
GetStringChars(JNIEnv * _env,jstring string,jboolean * isCopy)3554 GetStringChars (JNIEnv *_env, jstring string, jboolean *isCopy)
3555 {
3556 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3557 jcharArray chars;
3558 jchar *result = NULL;
3559
3560 assert (env == _svmf_get_current_env ());
3561
3562 _svmm_resuming_java (env);
3563
3564 if (_svmm_new_native_local_array (env, chars) != JNI_OK)
3565 {
3566 goto end;
3567 }
3568
3569 if (_svmm_invoke_static_stringcreator_getchars
3570 (env, string, _svmf_cast_jobject (chars)) != JNI_OK)
3571 {
3572 _svmm_free_native_local_array (env, chars);
3573 goto end;
3574 }
3575
3576 {
3577 jchar *elements = (jchar *) (void *)
3578 (((char *) *chars) +
3579 _svmf_aligned_size_t (sizeof (_svmt_array_instance)));
3580 jint size = (*chars)->size;
3581
3582 if (size == 0)
3583 {
3584 if (isCopy != NULL)
3585 {
3586 *isCopy = JNI_FALSE;
3587 }
3588
3589 result = elements;
3590
3591 _svmm_free_native_local_array (env, chars);
3592 goto end;
3593 }
3594
3595 if (_svmm_gmalloc_chars (env, size, result) != JNI_OK)
3596 {
3597 _svmm_free_native_local_array (env, chars);
3598 goto end;
3599 }
3600
3601 if (isCopy != NULL)
3602 {
3603 *isCopy = JNI_TRUE;
3604 }
3605
3606 memcpy (result, elements, size * sizeof (jchar));
3607 _svmm_free_native_local_array (env, chars);
3608
3609 }
3610
3611 end:
3612 _svmm_stopping_java (env);
3613
3614 return result;
3615 }
3616
3617 /*
3618 ----------------------------------------------------------------------
3619 ReleaseStringChars
3620 ----------------------------------------------------------------------
3621 */
3622
3623 JNIEXPORT svm_static void JNICALL
ReleaseStringChars(JNIEnv * _env,jstring string,const jchar * _chars)3624 ReleaseStringChars (JNIEnv *_env, jstring string, const jchar *_chars)
3625 {
3626 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3627
3628 assert (env == _svmf_get_current_env ());
3629
3630 _svmm_resuming_java (env);
3631
3632 {
3633 jint size;
3634
3635 if (_svmm_invoke_static_stringcreator_getlength (env, string, size) !=
3636 JNI_OK)
3637 {
3638 goto end;
3639 }
3640
3641 if (size != 0)
3642 {
3643 jchar *chars = (jchar *) _chars; /* to eliminate compile error */
3644 _svmm_gmfree_chars (chars);
3645 _chars = NULL;
3646 }
3647 }
3648
3649 end:
3650 _svmm_stopping_java (env);
3651 }
3652
3653 /*
3654 ----------------------------------------------------------------------
3655 GetObjectArrayElement
3656 ----------------------------------------------------------------------
3657 */
3658
3659 JNIEXPORT svm_static jobject JNICALL
GetObjectArrayElement(JNIEnv * _env,jobjectArray array,jsize indx)3660 GetObjectArrayElement (JNIEnv *_env, jobjectArray array, jsize indx)
3661 {
3662 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3663 jint size;
3664 jobject value = NULL;
3665
3666 assert (env == _svmf_get_current_env ());
3667
3668 _svmm_resuming_java (env);
3669
3670 {
3671 _svmt_object_instance *instance;
3672
3673 if (array == NULL)
3674 {
3675 _svmf_error_NullPointerException (env);
3676 goto end;
3677 }
3678
3679 size = (*array)->size;
3680
3681 if (((_svmt_u32) indx) >= (_svmt_u32) size)
3682 {
3683 _svmf_error_ArrayIndexOutOfBoundsException (env);
3684 goto end;
3685 }
3686
3687 instance = _svmf_get_reference_array_element (*array, indx);
3688 if (instance != NULL)
3689 {
3690 value = _svmf_get_jni_frame_native_local (env);
3691 *value = instance;
3692 }
3693 }
3694
3695 end:
3696 _svmm_stopping_java (env);
3697
3698 return value;
3699 }
3700
3701 /*
3702 ----------------------------------------------------------------------
3703 GetBooleanArrayElements
3704 ----------------------------------------------------------------------
3705 */
3706
3707 JNIEXPORT svm_static jboolean *JNICALL
GetBooleanArrayElements(JNIEnv * _env,jbooleanArray array SVM_UNUSED,jboolean * isCopy SVM_UNUSED)3708 GetBooleanArrayElements (JNIEnv *_env, jbooleanArray array SVM_UNUSED,
3709 jboolean *isCopy SVM_UNUSED)
3710 {
3711 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3712
3713 assert (env == _svmf_get_current_env ());
3714
3715 _svmm_resuming_java (env);
3716
3717 _svmm_fatal_error ("todo");
3718
3719 _svmm_stopping_java (env);
3720
3721 return NULL;
3722 }
3723
3724 /*
3725 ----------------------------------------------------------------------
3726 ReleaseBooleanArrayElements
3727 ----------------------------------------------------------------------
3728 */
3729
3730 JNIEXPORT svm_static void JNICALL
ReleaseBooleanArrayElements(JNIEnv * _env,jbooleanArray array SVM_UNUSED,jboolean * elems SVM_UNUSED,jint mode SVM_UNUSED)3731 ReleaseBooleanArrayElements (JNIEnv *_env, jbooleanArray array SVM_UNUSED,
3732 jboolean *elems SVM_UNUSED, jint mode SVM_UNUSED)
3733 {
3734 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3735
3736 assert (env == _svmf_get_current_env ());
3737
3738 _svmm_resuming_java (env);
3739
3740 _svmm_fatal_error ("todo");
3741
3742 _svmm_stopping_java (env);
3743 }
3744
3745 /*
3746 ----------------------------------------------------------------------
3747 GetBooleanArrayRegion
3748 ----------------------------------------------------------------------
3749 */
3750
3751 JNIEXPORT svm_static void JNICALL
GetBooleanArrayRegion(JNIEnv * _env,jbooleanArray array SVM_UNUSED,jsize start SVM_UNUSED,jsize len SVM_UNUSED,jboolean * buf SVM_UNUSED)3752 GetBooleanArrayRegion (JNIEnv *_env, jbooleanArray array SVM_UNUSED,
3753 jsize start SVM_UNUSED, jsize len SVM_UNUSED,
3754 jboolean *buf SVM_UNUSED)
3755 {
3756 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3757
3758 assert (env == _svmf_get_current_env ());
3759
3760 _svmm_resuming_java (env);
3761
3762 _svmm_fatal_error ("todo");
3763
3764 _svmm_stopping_java (env);
3765 }
3766
3767 /*
3768 ----------------------------------------------------------------------
3769 SetBooleanArrayRegion
3770 ----------------------------------------------------------------------
3771 */
3772
3773 JNIEXPORT svm_static void JNICALL
SetBooleanArrayRegion(JNIEnv * _env,jbooleanArray array SVM_UNUSED,jsize start SVM_UNUSED,jsize len SVM_UNUSED,jboolean * buf SVM_UNUSED)3774 SetBooleanArrayRegion (JNIEnv *_env, jbooleanArray array SVM_UNUSED,
3775 jsize start SVM_UNUSED, jsize len SVM_UNUSED,
3776 jboolean *buf SVM_UNUSED)
3777 {
3778 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3779
3780 assert (env == _svmf_get_current_env ());
3781
3782 _svmm_resuming_java (env);
3783
3784 _svmm_fatal_error ("todo");
3785
3786 _svmm_stopping_java (env);
3787 }
3788
3789 /*
3790 ----------------------------------------------------------------------
3791 RegisterNatives
3792 ----------------------------------------------------------------------
3793 */
3794
3795 JNIEXPORT svm_static jint JNICALL
RegisterNatives(JNIEnv * _env,jclass cls SVM_UNUSED,const JNINativeMethod * methods SVM_UNUSED,jint nMethods SVM_UNUSED)3796 RegisterNatives (JNIEnv *_env, jclass cls SVM_UNUSED,
3797 const JNINativeMethod *methods SVM_UNUSED,
3798 jint nMethods SVM_UNUSED)
3799 {
3800 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3801
3802 assert (env == _svmf_get_current_env ());
3803
3804 _svmm_resuming_java (env);
3805
3806 _svmm_fatal_error ("todo");
3807
3808 _svmm_stopping_java (env);
3809
3810 return JNI_ERR;
3811 }
3812
3813 /*
3814 ----------------------------------------------------------------------
3815 UnregisterNatives
3816 ----------------------------------------------------------------------
3817 */
3818
3819 JNIEXPORT svm_static jint JNICALL
UnregisterNatives(JNIEnv * _env,jclass cls SVM_UNUSED)3820 UnregisterNatives (JNIEnv *_env, jclass cls SVM_UNUSED)
3821 {
3822 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3823
3824 assert (env == _svmf_get_current_env ());
3825
3826 _svmm_resuming_java (env);
3827
3828 _svmm_fatal_error ("todo");
3829
3830 _svmm_stopping_java (env);
3831
3832 return JNI_ERR;
3833 }
3834
3835 /*
3836 ----------------------------------------------------------------------
3837 MonitorEnter
3838 ----------------------------------------------------------------------
3839 */
3840
3841 JNIEXPORT svm_static jint JNICALL
MonitorEnter(JNIEnv * _env,jobject obj)3842 MonitorEnter (JNIEnv *_env, jobject obj)
3843 {
3844 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3845
3846 jint result = JNI_ERR;
3847
3848 assert (env == _svmf_get_current_env ());
3849
3850 _svmm_resuming_java (env);
3851
3852 {
3853 if (obj == NULL)
3854 {
3855 _svmf_error_NullPointerException (env);
3856 goto end;
3857 }
3858
3859 if (_svmf_enter_object_monitor (env, *obj) != JNI_OK)
3860 {
3861 goto end;
3862 }
3863
3864 /* structured locking */
3865 env->stack.current_frame->lock_count++;
3866
3867 result = JNI_OK;
3868 }
3869
3870 end:
3871 _svmm_stopping_java (env);
3872
3873 return result;
3874 }
3875
3876 /*
3877 ----------------------------------------------------------------------
3878 MonitorExit
3879 ----------------------------------------------------------------------
3880 */
3881
3882 JNIEXPORT svm_static jint JNICALL
MonitorExit(JNIEnv * _env,jobject obj)3883 MonitorExit (JNIEnv *_env, jobject obj)
3884 {
3885 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3886
3887 jint result = JNI_ERR;
3888
3889 assert (env == _svmf_get_current_env ());
3890
3891 _svmm_resuming_java (env);
3892
3893 {
3894 if (obj == NULL)
3895 {
3896 _svmf_error_NullPointerException (env);
3897 goto end;
3898 }
3899
3900 /* structured locking */
3901 if (--(env->stack.current_frame->lock_count) < 0
3902 && env->vm->enforce_structured_locking)
3903 {
3904 _svmf_error_IllegalMonitorStateException (env);
3905 goto end;
3906 }
3907
3908 if (_svmf_exit_object_monitor (env, *obj) != JNI_OK)
3909 {
3910 goto end;
3911 }
3912
3913 result = JNI_OK;
3914 }
3915
3916 end:
3917 _svmm_stopping_java (env);
3918
3919 return result;
3920 }
3921
3922 /*
3923 ----------------------------------------------------------------------
3924 GetJavaVM
3925 ----------------------------------------------------------------------
3926 */
3927
3928 JNIEXPORT svm_static jint JNICALL
GetJavaVM(JNIEnv * _env,JavaVM ** vm)3929 GetJavaVM (JNIEnv *_env, JavaVM **vm)
3930 {
3931 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3932
3933 assert (env == _svmf_get_current_env ());
3934
3935 _svmm_resuming_java (env);
3936
3937 *vm = _svmf_cast_JavaVM (env->vm);
3938
3939 _svmm_stopping_java (env);
3940
3941 return JNI_OK;
3942 }
3943
3944 /*
3945 ----------------------------------------------------------------------
3946 EnsureLocalCapacity
3947 ----------------------------------------------------------------------
3948 */
3949
3950 JNIEXPORT svm_static jint JNICALL
EnsureLocalCapacity(JNIEnv * _env,jint capacity)3951 EnsureLocalCapacity (JNIEnv *_env, jint capacity)
3952 {
3953 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3954 jint result;
3955
3956 assert (env == _svmf_get_current_env ());
3957
3958 _svmm_resuming_java (env);
3959
3960 result = _svmf_ensure_native_local_capacity (env, capacity);
3961
3962 _svmm_stopping_java (env);
3963
3964 return result;
3965 }
3966
3967 /*
3968 ----------------------------------------------------------------------
3969 PushLocalFrame
3970 ----------------------------------------------------------------------
3971 */
3972
3973 JNIEXPORT svm_static jint JNICALL
PushLocalFrame(JNIEnv * _env,jint capacity)3974 PushLocalFrame (JNIEnv *_env, jint capacity)
3975 {
3976 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
3977 _svmt_stack_frame *frame = env->stack.current_frame;
3978 _svmt_stack_native_reference *lrefs;
3979
3980 jint lrefs_count = _svmf_max_jint (capacity, SVM_FRAME_NATIVE_REFS_MIN);
3981 size_t lrefs_size = _svmf_aligned_size_t
3982 ((lrefs_count + 2) * sizeof (_svmt_stack_native_reference));
3983 jint i;
3984 jint result = JNI_OK;
3985
3986 assert (env == _svmf_get_current_env ());
3987
3988 _svmm_resuming_java (env);
3989
3990 if (_svmf_ensure_stack_capacity (env, lrefs_size) != JNI_OK)
3991 {
3992 result = JNI_ERR;
3993 goto end;
3994 }
3995
3996 frame = env->stack.current_frame;
3997
3998 frame->end_offset += lrefs_size;
3999
4000 lrefs =
4001 (_svmt_stack_native_reference *) (void *) (((char *) frame) +
4002 frame->end_offset);
4003 lrefs[-1].jint = lrefs_count;
4004 lrefs[-2].size_t = lrefs_size;
4005
4006 lrefs =
4007 (_svmt_stack_native_reference *) (void *) (((char *) lrefs) - lrefs_size);
4008
4009 /* just in case we've ran out of memory during refs creation */
4010 memset (lrefs, 0, lrefs_count * sizeof (_svmt_stack_native_reference));
4011
4012 for (i = 0; i < lrefs_count; i++)
4013 {
4014 if (_svmm_new_native_local (env, lrefs[i].jobject) != JNI_OK)
4015 {
4016 result = JNI_ERR;
4017 goto end;
4018 }
4019 }
4020
4021 end:
4022 _svmm_stopping_java (env);
4023
4024 return result;
4025 }
4026
4027 /*
4028 ----------------------------------------------------------------------
4029 PopLocalFrame
4030 ----------------------------------------------------------------------
4031 */
4032
4033 JNIEXPORT svm_static jobject JNICALL
PopLocalFrame(JNIEnv * _env,jobject ref)4034 PopLocalFrame (JNIEnv *_env, jobject ref)
4035 {
4036 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4037 _svmt_stack_frame *frame = env->stack.current_frame;
4038 _svmt_stack_native_reference *lrefs =
4039 (_svmt_stack_native_reference *) (void *) (((char *) frame) +
4040 frame->end_offset);
4041
4042 jint lrefs_count = lrefs[-1].jint;
4043 size_t lrefs_size = lrefs[-2].size_t;
4044
4045 jint i;
4046 jobject result = NULL;
4047 _svmt_object_instance *saved_ref = NULL;
4048
4049 assert (env == _svmf_get_current_env ());
4050
4051 _svmm_resuming_java (env);
4052
4053 /* temporarily remember the direct address of the result object, if there
4054 is one, just in case ref is a local ref in the top localref frame
4055 (so ref will be freed below). */
4056 if (ref != NULL)
4057 {
4058 /* VERY IMPORTANT: As saved_ref is a direct pointer, we must make sure
4059 that we do not call any function that could potentially disturb the
4060 heap and cause GC. */
4061 saved_ref = *ref;
4062 }
4063
4064 lrefs =
4065 (_svmt_stack_native_reference *) (void *) (((char *) lrefs) - lrefs_size);
4066
4067 #ifndef NDEBUG
4068 /* Don't allow to pop the initial native frame.
4069 * Normally we don't check this as the JNI code is expected to be well-behaved,
4070 * according to the specs. */
4071
4072 if (!(lrefs > ((_svmt_stack_native_reference *) (void *)
4073 (((char *) frame) + _svmv_stack_offset))))
4074 {
4075 _svmm_fatal_error ("Trying to pop the initial local native frame.\n"
4076 "** This is a bug in the application you are trying to run.\n"
4077 "** It is not allowed to call PopLocalFrame() more times than\n"
4078 "** PushLocalFrame() has been called.\n");
4079 }
4080
4081 #endif
4082
4083 frame->end_offset -= lrefs_size;
4084
4085 for (i = 0; i < lrefs_count; i++)
4086 {
4087 if (lrefs[i].jobject !=NULL)
4088 {
4089 /* Does not affect the heap nor cause GC. See above
4090 comment. */
4091 _svmm_free_native_local (env, lrefs[i].jobject);
4092 }
4093 }
4094
4095 if (ref != NULL)
4096 {
4097 /* Does not affect the heap nor cause GC (unless FatalError is
4098 called). See above comment. */
4099 result = _svmf_get_jni_frame_native_local (env);
4100 *result = saved_ref;
4101 }
4102
4103 _svmm_stopping_java (env);
4104
4105 return result;
4106 }
4107
4108 /*
4109 ----------------------------------------------------------------------
4110 NewLocalRef
4111 ----------------------------------------------------------------------
4112 */
4113
4114 JNIEXPORT svm_static jobject JNICALL
NewLocalRef(JNIEnv * _env,jobject ref SVM_UNUSED)4115 NewLocalRef (JNIEnv *_env, jobject ref SVM_UNUSED)
4116 {
4117 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4118
4119 assert (env == _svmf_get_current_env ());
4120
4121 _svmm_resuming_java (env);
4122
4123 _svmm_fatal_error ("todo");
4124
4125 _svmm_stopping_java (env);
4126
4127 return NULL;
4128 }
4129
4130 /*
4131 ----------------------------------------------------------------------
4132 NewWeakGlobalRef
4133 ----------------------------------------------------------------------
4134 */
4135
4136 JNIEXPORT svm_static jweak JNICALL
NewWeakGlobalRef(JNIEnv * _env,jobject obj SVM_UNUSED)4137 NewWeakGlobalRef (JNIEnv *_env, jobject obj SVM_UNUSED)
4138 {
4139 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4140
4141 assert (env == _svmf_get_current_env ());
4142
4143 _svmm_resuming_java (env);
4144
4145 _svmm_fatal_error ("todo");
4146
4147 _svmm_stopping_java (env);
4148
4149 return NULL;
4150 }
4151
4152 /*
4153 ----------------------------------------------------------------------
4154 DeleteWeakGlobalRef
4155 ----------------------------------------------------------------------
4156 */
4157
4158 JNIEXPORT svm_static void JNICALL
DeleteWeakGlobalRef(JNIEnv * _env,jweak obj SVM_UNUSED)4159 DeleteWeakGlobalRef (JNIEnv *_env, jweak obj SVM_UNUSED)
4160 {
4161 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4162
4163 assert (env == _svmf_get_current_env ());
4164
4165 _svmm_resuming_java (env);
4166
4167 _svmm_fatal_error ("todo");
4168
4169 _svmm_stopping_java (env);
4170 }
4171
4172 /*
4173 ----------------------------------------------------------------------
4174 GetPrimitiveArrayCritical
4175 ----------------------------------------------------------------------
4176 */
4177
4178 JNIEXPORT svm_static void *JNICALL
GetPrimitiveArrayCritical(JNIEnv * _env,jarray array,jboolean * isCopy)4179 GetPrimitiveArrayCritical (JNIEnv *_env, jarray array, jboolean *isCopy)
4180 {
4181 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4182 void *result = NULL;
4183
4184 assert (env == _svmf_get_current_env ());
4185
4186 /* we only resume java if we are entering the critical section */
4187 if (env->critical_section_count == 0)
4188 {
4189 _svmm_resuming_java (env);
4190 }
4191
4192 /* it must be an non-null ref to an array */
4193 assert (array != NULL);
4194 assert ((*array)->vtable->type->is_array == JNI_TRUE);
4195
4196 {
4197 jint size = (*array)->size;
4198 _svmt_array_info *type = _svmf_cast_array ((*array)->vtable->type);
4199
4200 assert (type->dimensions == 1);
4201 assert (type->base_type != SVM_TYPE_VOID);
4202 assert (type->base_type != SVM_TYPE_REFERENCE);
4203
4204 /* if array has length 0, return some pointer != NULL */
4205 if (size == 0)
4206 {
4207 if (isCopy != NULL)
4208 {
4209 *isCopy = JNI_FALSE;
4210 }
4211
4212 /* As the length is 0, we might as well return a direct
4213 pointer to the elements. This way, we'll be sure the
4214 pointer is not NULL. */
4215 result = (void *) (((char *) *array) +
4216 _svmf_aligned_size_t (sizeof
4217 (_svmt_array_instance)));
4218
4219 /* we must record the number of times JNI code reenters this
4220 critical section. */
4221 env->critical_section_count++;
4222 }
4223 else if (type->base_type != SVM_TYPE_BOOLEAN)
4224 {
4225 /* if the array is not a boolean array, simply return a direct
4226 pointer to the elements */
4227
4228 if (isCopy != NULL)
4229 {
4230 *isCopy = JNI_FALSE;
4231 }
4232
4233 result = (void *) (((char *) *array) +
4234 _svmf_aligned_size_t (sizeof
4235 (_svmt_array_instance)));
4236
4237 /* we must record the number of times JNI code reenters this
4238 critical section. */
4239 env->critical_section_count++;
4240 }
4241 else
4242 {
4243 if (isCopy != NULL)
4244 {
4245 *isCopy = JNI_TRUE;
4246 }
4247
4248 _svmm_fatal_error ("todo");
4249 }
4250 }
4251
4252 /* in a critical section, we do not call _svmm_stopping_java (env); */
4253
4254 return result;
4255 }
4256
4257 /*
4258 ----------------------------------------------------------------------
4259 ReleasePrimitiveArrayCritical
4260 ----------------------------------------------------------------------
4261 */
4262
4263 JNIEXPORT svm_static void JNICALL
ReleasePrimitiveArrayCritical(JNIEnv * _env,jarray array,void * carray SVM_UNUSED,jint mode SVM_UNUSED)4264 ReleasePrimitiveArrayCritical (JNIEnv *_env, jarray array,
4265 void *carray SVM_UNUSED, jint mode SVM_UNUSED)
4266 {
4267 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4268
4269 assert (env == _svmf_get_current_env ());
4270
4271 /* in a critical section, we do not call _svmm_resuming_java (env); */
4272
4273 /* it must be an non-null ref to an array */
4274 assert (array != NULL);
4275 assert ((*array)->vtable->type->is_array == JNI_TRUE);
4276
4277 {
4278 jint size = (*array)->size;
4279 _svmt_array_info *type = _svmf_cast_array ((*array)->vtable->type);
4280
4281 assert (type->base_type != SVM_TYPE_VOID);
4282 assert (type->base_type != SVM_TYPE_REFERENCE);
4283
4284 /* if array has length 0, we have nothing to do */
4285 if (size == 0)
4286 {
4287 }
4288 else if (type->base_type != SVM_TYPE_BOOLEAN)
4289 {
4290 /* if the array is not a boolean array, we have nothing to
4291 do */
4292 }
4293 else
4294 {
4295 _svmm_fatal_error ("todo");
4296 }
4297 }
4298
4299 env->critical_section_count--;
4300
4301 if (env->critical_section_count == 0)
4302 {
4303 /* stepping out of a critical section */
4304 _svmm_stopping_java (env);
4305 }
4306 }
4307
4308 /*
4309 ----------------------------------------------------------------------
4310 GetStringRegion
4311 ----------------------------------------------------------------------
4312 */
4313
4314 JNIEXPORT svm_static void JNICALL
GetStringRegion(JNIEnv * _env,jstring str SVM_UNUSED,jsize start SVM_UNUSED,jsize len SVM_UNUSED,jchar * buf SVM_UNUSED)4315 GetStringRegion (JNIEnv *_env, jstring str SVM_UNUSED, jsize start SVM_UNUSED,
4316 jsize len SVM_UNUSED, jchar *buf SVM_UNUSED)
4317 {
4318 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4319
4320 assert (env == _svmf_get_current_env ());
4321
4322 _svmm_resuming_java (env);
4323
4324 _svmm_fatal_error ("todo");
4325
4326 _svmm_stopping_java (env);
4327 }
4328
4329 /*
4330 ----------------------------------------------------------------------
4331 GetStringUTFRegion
4332 ----------------------------------------------------------------------
4333 */
4334
4335 JNIEXPORT svm_static void JNICALL
GetStringUTFRegion(JNIEnv * _env,jstring str SVM_UNUSED,jsize start SVM_UNUSED,jsize len SVM_UNUSED,char * buf SVM_UNUSED)4336 GetStringUTFRegion (JNIEnv *_env, jstring str SVM_UNUSED,
4337 jsize start SVM_UNUSED, jsize len SVM_UNUSED,
4338 char *buf SVM_UNUSED)
4339 {
4340 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4341
4342 assert (env == _svmf_get_current_env ());
4343
4344 _svmm_resuming_java (env);
4345
4346 _svmm_fatal_error ("todo");
4347
4348 _svmm_stopping_java (env);
4349 }
4350
4351 /*
4352 ----------------------------------------------------------------------
4353 GetStringCritical
4354 ----------------------------------------------------------------------
4355 */
4356
4357 JNIEXPORT svm_static const jchar *JNICALL
GetStringCritical(JNIEnv * _env,jstring string SVM_UNUSED,jboolean * isCopy SVM_UNUSED)4358 GetStringCritical (JNIEnv *_env, jstring string SVM_UNUSED,
4359 jboolean *isCopy SVM_UNUSED)
4360 {
4361 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4362
4363 assert (env == _svmf_get_current_env ());
4364
4365 _svmm_resuming_java (env);
4366
4367 _svmm_fatal_error ("todo");
4368
4369 _svmm_stopping_java (env);
4370
4371 return NULL;
4372 }
4373
4374 /*
4375 ----------------------------------------------------------------------
4376 ReleaseStringCritical
4377 ----------------------------------------------------------------------
4378 */
4379
4380 JNIEXPORT svm_static void JNICALL
ReleaseStringCritical(JNIEnv * _env,jstring string SVM_UNUSED,const jchar * carray SVM_UNUSED)4381 ReleaseStringCritical (JNIEnv *_env, jstring string SVM_UNUSED,
4382 const jchar *carray SVM_UNUSED)
4383 {
4384 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4385
4386 assert (env == _svmf_get_current_env ());
4387
4388 _svmm_resuming_java (env);
4389
4390 _svmm_fatal_error ("todo");
4391
4392 _svmm_stopping_java (env);
4393 }
4394
4395 /*
4396 ----------------------------------------------------------------------
4397 FromReflectedMethod
4398 ----------------------------------------------------------------------
4399 */
4400
4401 JNIEXPORT svm_static jmethodID JNICALL
FromReflectedMethod(JNIEnv * _env,jobject method)4402 FromReflectedMethod (JNIEnv *_env, jobject method)
4403 {
4404 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4405 _svmt_JavaVM *vm = env->vm;
4406 _svmt_method_info *method_id;
4407
4408 assert (env == _svmf_get_current_env ());
4409
4410 _svmm_resuming_java (env);
4411
4412 if (_svmf_cast_class ((*method)->vtable->type) ==
4413 vm->class_loading.boot_loader.classes.jlrmethod)
4414 {
4415 method_id = _svmf_unwrap_method_instance (env, method);
4416 }
4417 else
4418 {
4419 assert (_svmf_cast_class ((*method)->vtable->type) ==
4420 vm->class_loading.boot_loader.classes.jlrconstructor);
4421
4422 method_id = _svmf_unwrap_constructor_instance (env, method);
4423 }
4424
4425 _svmm_stopping_java (env);
4426
4427 return method_id;
4428 }
4429
4430 /*
4431 ----------------------------------------------------------------------
4432 FromReflectedField
4433 ----------------------------------------------------------------------
4434 */
4435
4436 JNIEXPORT svm_static jfieldID JNICALL
FromReflectedField(JNIEnv * _env,jobject field)4437 FromReflectedField (JNIEnv *_env, jobject field)
4438 {
4439 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4440 _svmt_field_info *field_id;
4441
4442 assert (env == _svmf_get_current_env ());
4443
4444 _svmm_resuming_java (env);
4445
4446 field_id = _svmf_unwrap_field_instance (env, field);
4447
4448 _svmm_stopping_java (env);
4449
4450 return field_id;
4451 }
4452
4453 /*
4454 ----------------------------------------------------------------------
4455 ToReflectedMethod
4456 ----------------------------------------------------------------------
4457 */
4458
4459 JNIEXPORT svm_static jobject JNICALL
ToReflectedMethod(JNIEnv * _env,jclass cls SVM_UNUSED,jmethodID methodID,jboolean isStatic SVM_UNUSED)4460 ToReflectedMethod (JNIEnv *_env, jclass cls SVM_UNUSED,
4461 jmethodID methodID, jboolean isStatic SVM_UNUSED)
4462 {
4463 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4464 jobject method = NULL;
4465
4466 assert (env == _svmf_get_current_env ());
4467
4468 _svmm_resuming_java (env);
4469
4470 {
4471 _svmt_JavaVM *vm = env->vm;
4472
4473 method = _svmf_get_jni_frame_native_local (env);
4474
4475 if (methodID->reflection_instance == NULL)
4476 {
4477 /* create Method instance and cache it */
4478
4479 jbyteArray wrapper;
4480
4481 wrapper = _svmf_get_jni_frame_native_local_array (env);
4482 if (_svmm_local_wrap_pointer (env, methodID, wrapper) != JNI_OK)
4483 {
4484 goto end;
4485 }
4486
4487 if (DREF (methodID->name, value)[0] == '<')
4488 {
4489 /* Constructor */
4490
4491 if (_svmm_new_object_instance
4492 (env,
4493 vm->class_loading.boot_loader.classes.jlrconstructor,
4494 *method) != JNI_OK)
4495 {
4496 goto end;
4497 }
4498
4499 if (_svmm_invoke_nonvirtual_jlrconstructor_init
4500 (env, method, _svmf_cast_jobject (wrapper)) != JNI_OK)
4501 {
4502 goto end;
4503 }
4504
4505 }
4506 else
4507 {
4508 /* Method */
4509 if (_svmm_new_object_instance
4510 (env,
4511 vm->class_loading.boot_loader.classes.jlrmethod,
4512 *method) != JNI_OK)
4513 {
4514 goto end;
4515 }
4516
4517 if (_svmm_invoke_nonvirtual_jlrmethod_init
4518 (env, method, _svmf_cast_jobject (wrapper)) != JNI_OK)
4519 {
4520 goto end;
4521 }
4522 }
4523
4524
4525 if (_svmm_new_native_global
4526 (env, methodID->reflection_instance) != JNI_OK)
4527 {
4528 goto end;
4529 }
4530
4531 *(methodID->reflection_instance) = *method;
4532
4533 }
4534 else
4535 {
4536 *method = *(methodID->reflection_instance);
4537 }
4538
4539 }
4540
4541 end:
4542 _svmm_stopping_java (env);
4543
4544 return method;
4545 }
4546
4547 /*
4548 ----------------------------------------------------------------------
4549 ToReflectedField
4550 ----------------------------------------------------------------------
4551 */
4552
4553 JNIEXPORT svm_static jobject JNICALL
ToReflectedField(JNIEnv * _env,jclass cls SVM_UNUSED,jfieldID fieldID,jboolean isStatic SVM_UNUSED)4554 ToReflectedField (JNIEnv *_env, jclass cls SVM_UNUSED,
4555 jfieldID fieldID, jboolean isStatic SVM_UNUSED)
4556 {
4557 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4558 jobject field = NULL;
4559
4560 assert (env == _svmf_get_current_env ());
4561
4562 _svmm_resuming_java (env);
4563
4564 {
4565 _svmt_JavaVM *vm = env->vm;
4566
4567 field = _svmf_get_jni_frame_native_local (env);
4568
4569 if (fieldID->reflection_instance == NULL)
4570 {
4571 /* create Field instance and cache it */
4572
4573 jbyteArray wrapper;
4574
4575 wrapper = _svmf_get_jni_frame_native_local_array (env);
4576 if (_svmm_local_wrap_pointer (env, fieldID, wrapper) != JNI_OK)
4577 {
4578 goto end;
4579 }
4580
4581 if (_svmm_new_object_instance
4582 (env,
4583 vm->class_loading.boot_loader.classes.jlrfield,
4584 *field) != JNI_OK)
4585 {
4586 goto end;
4587 }
4588
4589 if (_svmm_invoke_nonvirtual_jlrfield_init
4590 (env, field, _svmf_cast_jobject (wrapper)) != JNI_OK)
4591 {
4592 goto end;
4593 }
4594
4595 if (_svmm_new_native_global
4596 (env, fieldID->reflection_instance) != JNI_OK)
4597 {
4598 goto end;
4599 }
4600
4601 *(fieldID->reflection_instance) = *field;
4602
4603 }
4604 else
4605 {
4606 *field = *(fieldID->reflection_instance);
4607 }
4608
4609 }
4610
4611 end:
4612 _svmm_stopping_java (env);
4613
4614 return field;
4615 }
4616
4617 /*
4618 ----------------------------------------------------------------------
4619 NewDirectByteBuffer
4620 ----------------------------------------------------------------------
4621 */
4622
4623 JNIEXPORT svm_static jobject JNICALL
NewDirectByteBuffer(JNIEnv * _env,void * address,jlong capacity)4624 NewDirectByteBuffer (JNIEnv *_env, void *address, jlong capacity)
4625 {
4626 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4627 jobject result = NULL;
4628
4629 assert (env == _svmf_get_current_env ());
4630
4631 _svmm_resuming_java (env);
4632
4633 result = _svmf_get_jni_frame_native_local (env);
4634
4635 #if SVM_WORD_BIT_COUNT == 32
4636
4637 if (_svmm_invoke_static_niobytebuffervm_newbuffer32
4638 (env, (jint) address, capacity, result) != JNI_OK)
4639 {
4640 _svmm_release_jni_frame_native_local (result);
4641 }
4642
4643 #elif SVM_WORD_BIT_COUNT == 64
4644
4645 if (_svmm_invoke_static_niobytebuffervm_newbuffer64
4646 (env, (jlong) address, capacity, result) != JNI_OK)
4647 {
4648 _svmm_release_jni_frame_native_local (result);
4649 }
4650
4651 #else
4652
4653 #error "todo: implement nio for non 32 or 64 bit platforms"
4654
4655 #endif
4656
4657 _svmm_stopping_java (env);
4658
4659 return result;
4660 }
4661
4662 /*
4663 ----------------------------------------------------------------------
4664 GetDirectBufferAddress
4665 ----------------------------------------------------------------------
4666 */
4667
4668 JNIEXPORT svm_static void *JNICALL
GetDirectBufferAddress(JNIEnv * _env,jobject buf)4669 GetDirectBufferAddress (JNIEnv *_env, jobject buf)
4670 {
4671 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4672 void *result = NULL;
4673
4674 assert (env == _svmf_get_current_env ());
4675
4676 _svmm_resuming_java (env);
4677
4678 #if SVM_WORD_BIT_COUNT == 32
4679
4680 {
4681 jint value;
4682
4683 if (_svmm_invoke_static_niobytebuffervm_getaddress32 (env, buf, value) ==
4684 JNI_OK)
4685 {
4686 result = (void *) value;
4687 }
4688 }
4689
4690 #elif SVM_WORD_BIT_COUNT == 64
4691
4692 {
4693 jlong value;
4694
4695 if (_svmm_invoke_static_niobytebuffervm_getaddress64 (env, buf, value) ==
4696 JNI_OK)
4697 {
4698 result = (void *) value;
4699 }
4700 }
4701
4702 #else
4703
4704 #error "todo: implement nio for non 32 or 64 bit platforms"
4705
4706 #endif
4707
4708 _svmm_stopping_java (env);
4709
4710 return result;
4711 }
4712
4713 /*
4714 ----------------------------------------------------------------------
4715 GetDirectBufferCapacity
4716 ----------------------------------------------------------------------
4717 */
4718
4719 JNIEXPORT svm_static jlong JNICALL
GetDirectBufferCapacity(JNIEnv * _env,jobject buf)4720 GetDirectBufferCapacity (JNIEnv *_env, jobject buf)
4721 {
4722 _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env);
4723 jlong result = -1;
4724
4725 assert (env == _svmf_get_current_env ());
4726
4727 _svmm_resuming_java (env);
4728
4729 if (_svmm_invoke_static_niobytebuffervm_getcapacity (env, buf, result) !=
4730 JNI_OK)
4731 {
4732 result = -1;
4733 }
4734
4735 _svmm_stopping_java (env);
4736
4737 return result;
4738 }
4739
4740
4741 /*
4742 ----------------------------------------------------------------------
4743 _svmv_native_interface
4744 ----------------------------------------------------------------------
4745 */
4746
4747 static const JNINativeInterface _svmv_native_interface = {
4748 NULL,
4749 NULL,
4750 NULL,
4751 NULL,
4752 GetVersion,
4753 DefineClass,
4754 FindClass,
4755 FromReflectedMethod,
4756 FromReflectedField,
4757 ToReflectedMethod,
4758 GetSuperclass,
4759 IsAssignableFrom,
4760 ToReflectedField,
4761 Throw,
4762 ThrowNew,
4763 ExceptionOccurred,
4764 ExceptionDescribe,
4765 ExceptionClear,
4766 FatalError,
4767 PushLocalFrame,
4768 PopLocalFrame,
4769 NewGlobalRef,
4770 DeleteGlobalRef,
4771 DeleteLocalRef,
4772 IsSameObject,
4773 NewLocalRef,
4774 EnsureLocalCapacity,
4775 AllocObject,
4776 NewObject,
4777 NewObjectV,
4778 NewObjectA,
4779 GetObjectClass,
4780 IsInstanceOf,
4781 GetMethodID,
4782 CallObjectMethod,
4783 CallObjectMethodV,
4784 CallObjectMethodA,
4785 CallBooleanMethod,
4786 CallBooleanMethodV,
4787 CallBooleanMethodA,
4788 CallByteMethod,
4789 CallByteMethodV,
4790 CallByteMethodA,
4791 CallCharMethod,
4792 CallCharMethodV,
4793 CallCharMethodA,
4794 CallShortMethod,
4795 CallShortMethodV,
4796 CallShortMethodA,
4797 CallIntMethod,
4798 CallIntMethodV,
4799 CallIntMethodA,
4800 CallLongMethod,
4801 CallLongMethodV,
4802 CallLongMethodA,
4803 CallFloatMethod,
4804 CallFloatMethodV,
4805 CallFloatMethodA,
4806 CallDoubleMethod,
4807 CallDoubleMethodV,
4808 CallDoubleMethodA,
4809 CallVoidMethod,
4810 CallVoidMethodV,
4811 CallVoidMethodA,
4812 CallNonvirtualObjectMethod,
4813 CallNonvirtualObjectMethodV,
4814 CallNonvirtualObjectMethodA,
4815 CallNonvirtualBooleanMethod,
4816 CallNonvirtualBooleanMethodV,
4817 CallNonvirtualBooleanMethodA,
4818 CallNonvirtualByteMethod,
4819 CallNonvirtualByteMethodV,
4820 CallNonvirtualByteMethodA,
4821 CallNonvirtualCharMethod,
4822 CallNonvirtualCharMethodV,
4823 CallNonvirtualCharMethodA,
4824 CallNonvirtualShortMethod,
4825 CallNonvirtualShortMethodV,
4826 CallNonvirtualShortMethodA,
4827 CallNonvirtualIntMethod,
4828 CallNonvirtualIntMethodV,
4829 CallNonvirtualIntMethodA,
4830 CallNonvirtualLongMethod,
4831 CallNonvirtualLongMethodV,
4832 CallNonvirtualLongMethodA,
4833 CallNonvirtualFloatMethod,
4834 CallNonvirtualFloatMethodV,
4835 CallNonvirtualFloatMethodA,
4836 CallNonvirtualDoubleMethod,
4837 CallNonvirtualDoubleMethodV,
4838 CallNonvirtualDoubleMethodA,
4839 CallNonvirtualVoidMethod,
4840 CallNonvirtualVoidMethodV,
4841 CallNonvirtualVoidMethodA,
4842 GetFieldID,
4843 GetObjectField,
4844 GetBooleanField,
4845 GetByteField,
4846 GetCharField,
4847 GetShortField,
4848 GetIntField,
4849 GetLongField,
4850 GetFloatField,
4851 GetDoubleField,
4852 SetObjectField,
4853 SetBooleanField,
4854 SetByteField,
4855 SetCharField,
4856 SetShortField,
4857 SetIntField,
4858 SetLongField,
4859 SetFloatField,
4860 SetDoubleField,
4861 GetStaticMethodID,
4862 CallStaticObjectMethod,
4863 CallStaticObjectMethodV,
4864 CallStaticObjectMethodA,
4865 CallStaticBooleanMethod,
4866 CallStaticBooleanMethodV,
4867 CallStaticBooleanMethodA,
4868 CallStaticByteMethod,
4869 CallStaticByteMethodV,
4870 CallStaticByteMethodA,
4871 CallStaticCharMethod,
4872 CallStaticCharMethodV,
4873 CallStaticCharMethodA,
4874 CallStaticShortMethod,
4875 CallStaticShortMethodV,
4876 CallStaticShortMethodA,
4877 CallStaticIntMethod,
4878 CallStaticIntMethodV,
4879 CallStaticIntMethodA,
4880 CallStaticLongMethod,
4881 CallStaticLongMethodV,
4882 CallStaticLongMethodA,
4883 CallStaticFloatMethod,
4884 CallStaticFloatMethodV,
4885 CallStaticFloatMethodA,
4886 CallStaticDoubleMethod,
4887 CallStaticDoubleMethodV,
4888 CallStaticDoubleMethodA,
4889 CallStaticVoidMethod,
4890 CallStaticVoidMethodV,
4891 CallStaticVoidMethodA,
4892 GetStaticFieldID,
4893 GetStaticObjectField,
4894 GetStaticBooleanField,
4895 GetStaticByteField,
4896 GetStaticCharField,
4897 GetStaticShortField,
4898 GetStaticIntField,
4899 GetStaticLongField,
4900 GetStaticFloatField,
4901 GetStaticDoubleField,
4902 SetStaticObjectField,
4903 SetStaticBooleanField,
4904 SetStaticByteField,
4905 SetStaticCharField,
4906 SetStaticShortField,
4907 SetStaticIntField,
4908 SetStaticLongField,
4909 SetStaticFloatField,
4910 SetStaticDoubleField,
4911 NewString,
4912 GetStringLength,
4913 GetStringChars,
4914 ReleaseStringChars,
4915 NewStringUTF,
4916 GetStringUTFLength,
4917 GetStringUTFChars,
4918 ReleaseStringUTFChars,
4919 GetArrayLength,
4920 NewObjectArray,
4921 GetObjectArrayElement,
4922 SetObjectArrayElement,
4923 NewBooleanArray,
4924 NewByteArray,
4925 NewCharArray,
4926 NewShortArray,
4927 NewIntArray,
4928 NewLongArray,
4929 NewFloatArray,
4930 NewDoubleArray,
4931 GetBooleanArrayElements,
4932 GetByteArrayElements,
4933 GetCharArrayElements,
4934 GetShortArrayElements,
4935 GetIntArrayElements,
4936 GetLongArrayElements,
4937 GetFloatArrayElements,
4938 GetDoubleArrayElements,
4939 ReleaseBooleanArrayElements,
4940 ReleaseByteArrayElements,
4941 ReleaseCharArrayElements,
4942 ReleaseShortArrayElements,
4943 ReleaseIntArrayElements,
4944 ReleaseLongArrayElements,
4945 ReleaseFloatArrayElements,
4946 ReleaseDoubleArrayElements,
4947 GetBooleanArrayRegion,
4948 GetByteArrayRegion,
4949 GetCharArrayRegion,
4950 GetShortArrayRegion,
4951 GetIntArrayRegion,
4952 GetLongArrayRegion,
4953 GetFloatArrayRegion,
4954 GetDoubleArrayRegion,
4955 SetBooleanArrayRegion,
4956 SetByteArrayRegion,
4957 SetCharArrayRegion,
4958 SetShortArrayRegion,
4959 SetIntArrayRegion,
4960 SetLongArrayRegion,
4961 SetFloatArrayRegion,
4962 SetDoubleArrayRegion,
4963 RegisterNatives,
4964 UnregisterNatives,
4965 MonitorEnter,
4966 MonitorExit,
4967 GetJavaVM,
4968 GetStringRegion,
4969 GetStringUTFRegion,
4970 GetPrimitiveArrayCritical,
4971 ReleasePrimitiveArrayCritical,
4972 GetStringCritical,
4973 ReleaseStringCritical,
4974 NewWeakGlobalRef,
4975 DeleteWeakGlobalRef,
4976 ExceptionCheck,
4977 NewDirectByteBuffer,
4978 GetDirectBufferAddress,
4979 GetDirectBufferCapacity
4980 };
4981
4982 /* end of file *[::]/
4983
4984 m4svm_off() */
4985