Line data Source code
1 : /* src/vm/primitive.cpp - primitive types
2 :
3 : Copyright (C) 2007-2013
4 : CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 :
6 : This file is part of CACAO.
7 :
8 : This program is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU General Public License as
10 : published by the Free Software Foundation; either version 2, or (at
11 : your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 : 02110-1301, USA.
22 :
23 : */
24 :
25 :
26 : #include "config.h"
27 :
28 : #include <assert.h>
29 : #include <stdint.h>
30 :
31 : #include "native/llni.hpp"
32 :
33 : #include "toolbox/logging.hpp"
34 :
35 : #include "vm/jit/builtin.hpp"
36 : #include "vm/class.hpp"
37 : #include "vm/global.hpp"
38 : #include "vm/globals.hpp"
39 : #include "vm/javaobjects.hpp"
40 : #include "vm/options.hpp"
41 : #include "vm/os.hpp"
42 : #include "vm/primitive.hpp"
43 : #include "vm/utf8.hpp"
44 : #include "vm/vm.hpp"
45 :
46 :
47 : /* primitivetype_table *********************************************************
48 :
49 : Structure for primitive classes: contains the class for wrapping
50 : the primitive type, the primitive class, the name of the class for
51 : wrapping, the one character type signature and the name of the
52 : primitive class.
53 :
54 : CAUTION: Don't change the order of the types. This table is indexed
55 : by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
56 :
57 : *******************************************************************************/
58 :
59 165 : primitivetypeinfo primitivetype_table[PRIMITIVETYPE_MAX] = {
60 : { "int" , NULL, NULL, NULL, "java/lang/Integer", 'I', "[I", NULL },
61 : { "long" , NULL, NULL, NULL, "java/lang/Long", 'J', "[J", NULL },
62 : { "float" , NULL, NULL, NULL, "java/lang/Float", 'F', "[F", NULL },
63 : { "double" , NULL, NULL, NULL, "java/lang/Double", 'D', "[D", NULL },
64 : { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
65 : { "byte" , NULL, NULL, NULL, "java/lang/Byte", 'B', "[B", NULL },
66 : { "char" , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
67 : { "short" , NULL, NULL, NULL, "java/lang/Short", 'S', "[S", NULL },
68 : { "boolean" , NULL, NULL, NULL, "java/lang/Boolean", 'Z', "[Z", NULL },
69 : { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
70 : #if defined(ENABLE_JAVASE)
71 : { "void" , NULL, NULL, NULL, "java/lang/Void", 'V', NULL, NULL }
72 : #else
73 : { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
74 : #endif
75 165 : };
76 :
77 :
78 : /**
79 : * Fill the primitive type table with the primitive-type classes,
80 : * array-classes and wrapper classes. This is important in the VM
81 : * startup.
82 : *
83 : * We split this primitive-type table initialization because of
84 : * annotations in the bootstrap classes.
85 : *
86 : * But we may get a problem if we have annotations in:
87 : *
88 : * java/lang/Object
89 : * java/lang/Cloneable
90 : * java/io/Serializable
91 : *
92 : * Also see: loader_preinit and linker_preinit.
93 : */
94 163 : void Primitive::initialize_table()
95 : {
96 163 : TRACESUBSYSTEMINITIALIZATION("primitive_init");
97 :
98 : /* Load and link primitive-type classes and array-classes. */
99 :
100 1956 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++) {
101 : /* Skip dummy entries. */
102 :
103 1793 : if (primitivetype_table[i].cname == NULL)
104 326 : continue;
105 :
106 : /* create UTF-8 name */
107 :
108 1467 : Utf8String name = Utf8String::from_utf8(primitivetype_table[i].cname);
109 :
110 1467 : primitivetype_table[i].name = name;
111 :
112 : /* create primitive class */
113 :
114 1467 : classinfo *c = class_create_classinfo(name);
115 :
116 : /* Primitive type classes don't have a super class. */
117 :
118 1467 : c->super = NULL;
119 :
120 : /* set flags and mark it as primitive class */
121 :
122 1467 : c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
123 :
124 : /* prevent loader from loading primitive class */
125 :
126 1467 : c->state |= CLASS_LOADED;
127 :
128 : /* INFO: don't put primitive classes into the classcache */
129 :
130 1467 : if (!link_class(c))
131 0 : vm_abort("linker_init: linking failed");
132 :
133 : /* Just to be sure. */
134 :
135 1467 : assert(c->state & CLASS_LOADED);
136 1467 : assert(c->state & CLASS_LINKED);
137 :
138 1467 : primitivetype_table[i].class_primitive = c;
139 :
140 : /* Create primitive array class. */
141 :
142 1467 : if (primitivetype_table[i].arrayname != NULL) {
143 1304 : Utf8String u = Utf8String::from_utf8(primitivetype_table[i].arrayname);
144 1304 : classinfo *ac = class_create_classinfo(u);
145 1304 : ac = load_newly_created_array(ac, NULL);
146 :
147 1304 : if (ac == NULL)
148 0 : vm_abort("primitive_init: loading failed");
149 :
150 1304 : assert(ac->state & CLASS_LOADED);
151 :
152 1304 : if (!link_class(ac))
153 0 : vm_abort("primitive_init: linking failed");
154 :
155 : /* Just to be sure. */
156 :
157 1304 : assert(ac->state & CLASS_LOADED);
158 1304 : assert(ac->state & CLASS_LINKED);
159 :
160 1304 : primitivetype_table[i].arrayclass = ac;
161 : }
162 : }
163 :
164 : /* We use two for-loops to have the array-classes already in the
165 : primitive-type table (hint: annotations in wrapper-classes). */
166 :
167 1956 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++) {
168 : /* Skip dummy entries. */
169 :
170 1793 : if (primitivetype_table[i].cname == NULL)
171 326 : continue;
172 :
173 : /* Create class for wrapping the primitive type. */
174 :
175 1467 : Utf8String u = Utf8String::from_utf8(primitivetype_table[i].wrapname);
176 1467 : classinfo *c = load_class_bootstrap(u);
177 :
178 1467 : if (c == NULL)
179 0 : vm_abort("primitive_init: loading failed");
180 :
181 1467 : if (!link_class(c))
182 0 : vm_abort("primitive_init: linking failed");
183 :
184 : /* Just to be sure. */
185 :
186 1467 : assert(c->state & CLASS_LOADED);
187 1467 : assert(c->state & CLASS_LINKED);
188 :
189 1467 : primitivetype_table[i].class_wrap = c;
190 : }
191 163 : }
192 :
193 :
194 : /**
195 : * Finish the primitive-type table initialization. In this step we
196 : * set the vftbl of the primitive-type classes.
197 : *
198 : * This is necessary because java/lang/Class is loaded and linked
199 : * after the primitive types have been linked.
200 : *
201 : * We have to do that in an extra function, as the primitive types are
202 : * not stored in the classcache.
203 : */
204 163 : void Primitive::post_initialize_table()
205 : {
206 163 : TRACESUBSYSTEMINITIALIZATION("primitive_postinit");
207 :
208 163 : assert(class_java_lang_Class);
209 163 : assert(class_java_lang_Class->vftbl);
210 :
211 1956 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++) {
212 : /* Skip dummy entries. */
213 :
214 1793 : if (primitivetype_table[i].cname == NULL)
215 326 : continue;
216 :
217 1467 : classinfo *c = primitivetype_table[i].class_primitive;
218 :
219 1467 : c->object.header.vftbl = class_java_lang_Class->vftbl;
220 : }
221 163 : }
222 :
223 :
224 : /**
225 : * Returns the primitive class of the given class name.
226 : *
227 : * @param name Name of the class.
228 : *
229 : * @return Class structure.
230 : */
231 0 : classinfo* Primitive::get_class_by_name(Utf8String name)
232 : {
233 : /* search table of primitive classes */
234 :
235 0 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++)
236 0 : if (primitivetype_table[i].name == name)
237 0 : return primitivetype_table[i].class_primitive;
238 :
239 : /* keep compiler happy */
240 :
241 0 : assert(false);
242 : return NULL;
243 : }
244 :
245 :
246 : /**
247 : * Returns the primitive class of the given type.
248 : *
249 : * @param type Integer type of the class.
250 : *
251 : * @return Class structure.
252 : */
253 444 : classinfo* Primitive::get_class_by_type(int type)
254 : {
255 444 : return primitivetype_table[type].class_primitive;
256 : }
257 :
258 :
259 : /**
260 : * Returns the primitive class of the given type.
261 : *
262 : * @param ch
263 : *
264 : * @return Class structure.
265 : */
266 1773 : classinfo* Primitive::get_class_by_char(char ch)
267 : {
268 : int index;
269 :
270 1773 : switch (ch) {
271 : case 'I':
272 304 : index = PRIMITIVETYPE_INT;
273 304 : break;
274 : case 'J':
275 177 : index = PRIMITIVETYPE_LONG;
276 177 : break;
277 : case 'F':
278 173 : index = PRIMITIVETYPE_FLOAT;
279 173 : break;
280 : case 'D':
281 174 : index = PRIMITIVETYPE_DOUBLE;
282 174 : break;
283 : case 'B':
284 166 : index = PRIMITIVETYPE_BYTE;
285 166 : break;
286 : case 'C':
287 304 : index = PRIMITIVETYPE_CHAR;
288 304 : break;
289 : case 'S':
290 168 : index = PRIMITIVETYPE_SHORT;
291 168 : break;
292 : case 'Z':
293 304 : index = PRIMITIVETYPE_BOOLEAN;
294 304 : break;
295 : case 'V':
296 3 : index = PRIMITIVETYPE_VOID;
297 3 : break;
298 : default:
299 0 : return NULL;
300 : }
301 :
302 1773 : return primitivetype_table[index].class_primitive;
303 : }
304 :
305 :
306 : /**
307 : * Returns the primitive array-class of the given primitive class
308 : * name.
309 : *
310 : * @param name Name of the class.
311 : *
312 : * @return Class structure.
313 : */
314 0 : classinfo* Primitive::get_arrayclass_by_name(Utf8String name)
315 : {
316 : /* search table of primitive classes */
317 :
318 0 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++)
319 0 : if (primitivetype_table[i].name == name)
320 0 : return primitivetype_table[i].arrayclass;
321 :
322 : /* keep compiler happy */
323 :
324 0 : assert(false);
325 : return NULL;
326 : }
327 :
328 :
329 : /**
330 : * Returns the primitive array-class of the given type.
331 : *
332 : * @param type Integer type of the class.
333 : *
334 : * @return Class structure.
335 : */
336 64470 : classinfo* Primitive::get_arrayclass_by_type(int type)
337 : {
338 64470 : return primitivetype_table[type].arrayclass;
339 : }
340 :
341 :
342 : /**
343 : * Returns the primitive type of the given wrapper-class.
344 : *
345 : * @param c Class structure.
346 : *
347 : * @return Integer type of the class.
348 : */
349 88 : int Primitive::get_type_by_wrapperclass(classinfo *c)
350 : {
351 : /* Search primitive table. */
352 :
353 88 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++)
354 88 : if (primitivetype_table[i].class_wrap == c)
355 88 : return i;
356 :
357 : /* Invalid primitive wrapper-class. */
358 :
359 0 : return -1;
360 : }
361 :
362 :
363 : /**
364 : * Returns the primitive type of the given primitive-class.
365 : *
366 : * @param c Class structure.
367 : *
368 : * @return Integer type of the class.
369 : */
370 0 : int Primitive::get_type_by_primitiveclass(classinfo *c)
371 : {
372 : /* Search primitive table. */
373 :
374 0 : for (int i = 0; i < PRIMITIVETYPE_MAX; i++)
375 0 : if (primitivetype_table[i].class_primitive == c)
376 0 : return i;
377 :
378 : /* Invalid primitive class. */
379 :
380 0 : return -1;
381 : }
382 :
383 :
384 : /**
385 : * Box a primitive of the given type. If the type is an object,
386 : * simply return it.
387 : *
388 : * @param type Type of the passed value.
389 : * @param value Value to box.
390 : *
391 : * @return Handle of the boxing Java object.
392 : */
393 577 : java_handle_t* Primitive::box(int type, imm_union value)
394 : {
395 : java_handle_t* o;
396 :
397 577 : switch (type) {
398 : case PRIMITIVETYPE_BOOLEAN:
399 0 : o = box((uint8_t) value.i);
400 0 : break;
401 : case PRIMITIVETYPE_BYTE:
402 6 : o = box((int8_t) value.i);
403 6 : break;
404 : case PRIMITIVETYPE_CHAR:
405 6 : o = box((uint16_t) value.i);
406 6 : break;
407 : case PRIMITIVETYPE_SHORT:
408 6 : o = box((int16_t) value.i);
409 6 : break;
410 : case PRIMITIVETYPE_INT:
411 40 : o = box(value.i);
412 40 : break;
413 : case PRIMITIVETYPE_LONG:
414 6 : o = box(value.l);
415 6 : break;
416 : case PRIMITIVETYPE_FLOAT:
417 7 : o = box(value.f);
418 7 : break;
419 : case PRIMITIVETYPE_DOUBLE:
420 7 : o = box(value.d);
421 7 : break;
422 : case PRIMITIVETYPE_VOID:
423 499 : o = (java_handle_t*) value.a;
424 499 : break;
425 : default:
426 0 : o = NULL;
427 0 : os::abort("Primitive::box: Invalid primitive type %d", type);
428 : }
429 :
430 577 : return o;
431 : }
432 :
433 :
434 : /**
435 : * Unbox a primitive of the given type. If the type is an object,
436 : * simply return it.
437 : *
438 : * @param h Handle of the Java object.
439 : *
440 : * @return Unboxed value as union.
441 : */
442 44 : imm_union Primitive::unbox(java_handle_t *h)
443 : {
444 : classinfo *c;
445 : imm_union value;
446 :
447 44 : if (h == NULL) {
448 0 : value.a = NULL;
449 0 : return value;
450 : }
451 :
452 44 : LLNI_class_get(h, c);
453 :
454 44 : int type = get_type_by_wrapperclass(c);
455 :
456 44 : switch (type) {
457 : case PRIMITIVETYPE_BOOLEAN:
458 0 : value.i = unbox_boolean(h);
459 0 : break;
460 : case PRIMITIVETYPE_BYTE:
461 0 : value.i = unbox_byte(h);
462 0 : break;
463 : case PRIMITIVETYPE_CHAR:
464 0 : value.i = unbox_char(h);
465 0 : break;
466 : case PRIMITIVETYPE_SHORT:
467 0 : value.i = unbox_short(h);
468 0 : break;
469 : case PRIMITIVETYPE_INT:
470 44 : value.i = unbox_int(h);
471 44 : break;
472 : case PRIMITIVETYPE_LONG:
473 0 : value.l = unbox_long(h);
474 0 : break;
475 : case PRIMITIVETYPE_FLOAT:
476 0 : value.f = unbox_float(h);
477 0 : break;
478 : case PRIMITIVETYPE_DOUBLE:
479 0 : value.d = unbox_double(h);
480 0 : break;
481 : case -1:
482 : /* If type is -1 the object is not a primitive box but a
483 : normal object. */
484 0 : value.a = h;
485 0 : break;
486 : default:
487 0 : os::abort("Primitive::unbox: Invalid primitive type %d", type);
488 : }
489 :
490 44 : return value;
491 : }
492 :
493 :
494 : /**
495 : * Unbox a primitive of the given type. Also checks if the
496 : * boxed primitive type can be widened into the destination
497 : * type. This conversion is done according to
498 : * "The Java Language Specification, Third Edition,
499 : * $5.1.2 Widening Primitive Conversion".
500 : *
501 : * @param h Handle of the boxing Java object.
502 : * @param type Destination type of the conversion.
503 : * @param value Pointer to union where the resulting primitive
504 : * value will be stored will.
505 : *
506 : * @return True of the conversion is allowed, false otherwise.
507 : */
508 0 : bool Primitive::unbox_typed(java_handle_t *h, int type, imm_union* value)
509 : {
510 : classinfo *c;
511 : int src_type;
512 :
513 0 : if (h == NULL)
514 0 : return false;
515 :
516 0 : LLNI_class_get(h, c);
517 :
518 0 : src_type = get_type_by_wrapperclass(c);
519 :
520 0 : switch (src_type) {
521 : case PRIMITIVETYPE_BOOLEAN:
522 0 : switch (type) {
523 : case PRIMITIVETYPE_BOOLEAN:
524 0 : value->i = unbox_boolean(h);
525 0 : return true;
526 : default:
527 0 : return false;
528 : }
529 :
530 : case PRIMITIVETYPE_BYTE:
531 0 : switch (type) {
532 : case PRIMITIVETYPE_BYTE:
533 : case PRIMITIVETYPE_SHORT:
534 : case PRIMITIVETYPE_INT:
535 0 : value->i = unbox_byte(h);
536 0 : return true;
537 : case PRIMITIVETYPE_LONG:
538 0 : value->l = unbox_byte(h);
539 0 : return true;
540 : case PRIMITIVETYPE_FLOAT:
541 0 : value->f = unbox_byte(h);
542 0 : return true;
543 : case PRIMITIVETYPE_DOUBLE:
544 0 : value->d = unbox_byte(h);
545 0 : return true;
546 : default:
547 0 : return false;
548 : }
549 :
550 : case PRIMITIVETYPE_CHAR:
551 0 : switch (type) {
552 : case PRIMITIVETYPE_CHAR:
553 : case PRIMITIVETYPE_INT:
554 0 : value->i = unbox_char(h);
555 0 : return true;
556 : case PRIMITIVETYPE_LONG:
557 0 : value->l = unbox_char(h);
558 0 : return true;
559 : case PRIMITIVETYPE_FLOAT:
560 0 : value->f = unbox_char(h);
561 0 : return true;
562 : case PRIMITIVETYPE_DOUBLE:
563 0 : value->d = unbox_char(h);
564 0 : return true;
565 : default:
566 0 : return false;
567 : }
568 :
569 : case PRIMITIVETYPE_SHORT:
570 0 : switch (type) {
571 : case PRIMITIVETYPE_SHORT:
572 : case PRIMITIVETYPE_INT:
573 0 : value->i = unbox_short(h);
574 0 : return true;
575 : case PRIMITIVETYPE_LONG:
576 0 : value->l = unbox_short(h);
577 0 : return true;
578 : case PRIMITIVETYPE_FLOAT:
579 0 : value->f = unbox_short(h);
580 0 : return true;
581 : case PRIMITIVETYPE_DOUBLE:
582 0 : value->d = unbox_short(h);
583 0 : return true;
584 : default:
585 0 : return false;
586 : }
587 :
588 : case PRIMITIVETYPE_INT:
589 0 : switch (type) {
590 : case PRIMITIVETYPE_INT:
591 0 : value->i = unbox_int(h);
592 0 : return true;
593 : case PRIMITIVETYPE_LONG:
594 0 : value->l = unbox_int(h);
595 0 : return true;
596 : case PRIMITIVETYPE_FLOAT:
597 0 : value->f = unbox_int(h);
598 0 : return true;
599 : case PRIMITIVETYPE_DOUBLE:
600 0 : value->d = unbox_int(h);
601 0 : return true;
602 : default:
603 0 : return false;
604 : }
605 :
606 : case PRIMITIVETYPE_LONG:
607 0 : switch (type) {
608 : case PRIMITIVETYPE_LONG:
609 0 : value->l = unbox_long(h);
610 0 : return true;
611 : case PRIMITIVETYPE_FLOAT:
612 0 : value->f = unbox_long(h);
613 0 : return true;
614 : case PRIMITIVETYPE_DOUBLE:
615 0 : value->d = unbox_long(h);
616 0 : return true;
617 : default:
618 0 : return false;
619 : }
620 :
621 : case PRIMITIVETYPE_FLOAT:
622 0 : switch (type) {
623 : case PRIMITIVETYPE_FLOAT:
624 0 : value->f = unbox_float(h);
625 0 : return true;
626 : case PRIMITIVETYPE_DOUBLE:
627 0 : value->d = unbox_float(h);
628 0 : return true;
629 : default:
630 0 : return false;
631 : }
632 :
633 : case PRIMITIVETYPE_DOUBLE:
634 0 : switch (type) {
635 : case PRIMITIVETYPE_DOUBLE:
636 0 : value->d = unbox_double(h);
637 0 : return true;
638 : default:
639 0 : return false;
640 : }
641 :
642 : default:
643 0 : os::abort("Primitive::unbox_typed: Invalid primitive type %d", type);
644 0 : return false;
645 : }
646 : }
647 :
648 :
649 : /**
650 : * Box a primitive type.
651 : */
652 0 : java_handle_t* Primitive::box(uint8_t value)
653 : {
654 0 : java_handle_t *h = builtin_new(class_java_lang_Boolean);
655 :
656 0 : if (h == NULL)
657 0 : return NULL;
658 :
659 0 : java_lang_Boolean b(h);
660 0 : b.set_value(value);
661 :
662 0 : return h;
663 : }
664 :
665 6 : java_handle_t* Primitive::box(int8_t value)
666 : {
667 6 : java_handle_t *h = builtin_new(class_java_lang_Byte);
668 :
669 6 : if (h == NULL)
670 0 : return NULL;
671 :
672 6 : java_lang_Byte b(h);
673 6 : b.set_value(value);
674 :
675 6 : return h;
676 : }
677 :
678 6 : java_handle_t* Primitive::box(uint16_t value)
679 : {
680 6 : java_handle_t *h = builtin_new(class_java_lang_Character);
681 :
682 6 : if (h == NULL)
683 0 : return NULL;
684 :
685 6 : java_lang_Character c(h);
686 6 : c.set_value(value);
687 :
688 6 : return h;
689 : }
690 :
691 6 : java_handle_t* Primitive::box(int16_t value)
692 : {
693 6 : java_handle_t *h = builtin_new(class_java_lang_Short);
694 :
695 6 : if (h == NULL)
696 0 : return NULL;
697 :
698 6 : java_lang_Short s(h);
699 6 : s.set_value(value);
700 :
701 6 : return h;
702 : }
703 :
704 40 : java_handle_t* Primitive::box(int32_t value)
705 : {
706 40 : java_handle_t *h = builtin_new(class_java_lang_Integer);
707 :
708 40 : if (h == NULL)
709 0 : return NULL;
710 :
711 40 : java_lang_Integer i(h);
712 40 : i.set_value(value);
713 :
714 40 : return h;
715 : }
716 :
717 6 : java_handle_t* Primitive::box(int64_t value)
718 : {
719 6 : java_handle_t *h = builtin_new(class_java_lang_Long);
720 :
721 6 : if (h == NULL)
722 0 : return NULL;
723 :
724 6 : java_lang_Long l(h);
725 6 : l.set_value(value);
726 :
727 6 : return h;
728 : }
729 :
730 7 : java_handle_t* Primitive::box(float value)
731 : {
732 7 : java_handle_t *h = builtin_new(class_java_lang_Float);
733 :
734 7 : if (h == NULL)
735 0 : return NULL;
736 :
737 7 : java_lang_Float f(h);
738 7 : f.set_value(value);
739 :
740 7 : return h;
741 : }
742 :
743 7 : java_handle_t* Primitive::box(double value)
744 : {
745 7 : java_handle_t *h = builtin_new(class_java_lang_Double);
746 :
747 7 : if (h == NULL)
748 0 : return NULL;
749 :
750 7 : java_lang_Double d(h);
751 7 : d.set_value(value);
752 :
753 7 : return h;
754 : }
755 :
756 :
757 :
758 : /**
759 : * Unbox a primitive type.
760 : */
761 :
762 : // template<class T> T Primitive::unbox(java_handle_t *h)
763 : // {
764 : // return java_lang_Boolean::get_value(h);
765 : // }
766 :
767 0 : inline uint8_t Primitive::unbox_boolean(java_handle_t *h)
768 : {
769 0 : java_lang_Boolean b(h);
770 0 : return b.get_value();
771 : }
772 :
773 0 : inline int8_t Primitive::unbox_byte(java_handle_t *h)
774 : {
775 0 : java_lang_Byte b(h);
776 0 : return b.get_value();
777 : }
778 :
779 0 : inline uint16_t Primitive::unbox_char(java_handle_t *h)
780 : {
781 0 : java_lang_Character c(h);
782 0 : return c.get_value();
783 : }
784 :
785 0 : inline int16_t Primitive::unbox_short(java_handle_t *h)
786 : {
787 0 : java_lang_Short s(h);
788 0 : return s.get_value();
789 : }
790 :
791 44 : inline int32_t Primitive::unbox_int(java_handle_t *h)
792 : {
793 44 : java_lang_Integer i(h);
794 44 : return i.get_value();
795 : }
796 :
797 0 : inline int64_t Primitive::unbox_long(java_handle_t *h)
798 : {
799 0 : java_lang_Long l(h);
800 0 : return l.get_value();
801 : }
802 :
803 0 : inline float Primitive::unbox_float(java_handle_t *h)
804 : {
805 0 : java_lang_Float f(h);
806 0 : return f.get_value();
807 : }
808 :
809 0 : inline double Primitive::unbox_double(java_handle_t *h)
810 : {
811 0 : java_lang_Double d(h);
812 0 : return d.get_value();
813 495 : }
814 :
815 :
816 : /*
817 : * These are local overrides for various environment variables in Emacs.
818 : * Please do not remove this and leave it at the end of the file, where
819 : * Emacs will automagically detect them.
820 : * ---------------------------------------------------------------------
821 : * Local variables:
822 : * mode: c++
823 : * indent-tabs-mode: t
824 : * c-basic-offset: 4
825 : * tab-width: 4
826 : * End:
827 : * vim:noexpandtab:sw=4:ts=4:
828 : */
|