1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
49 return ciConstant();
50 assert(ary->is_array(), "");
51 if (index < 0 || index >= ary->length())
52 return ciConstant();
53 ArrayKlass* ak = (ArrayKlass*) ary->klass();
54 BasicType abt = ak->element_type();
55 if (fixup_element_type(elembt) !=
56 fixup_element_type(abt))
57 return ciConstant();
58 switch (elembt) {
59 case T_ARRAY:
60 case T_OBJECT:
61 {
62 assert(ary->is_objArray(), "");
63 objArrayOop objary = (objArrayOop) ary;
64 oop elem = objary->obj_at(index);
65 ciEnv* env = CURRENT_ENV;
66 ciObject* box = env->get_object(elem);
67 return ciConstant(T_OBJECT, box);
68 }
69 }
70 assert(ary->is_typeArray(), "");
71 typeArrayOop tary = (typeArrayOop) ary;
72 jint value = 0;
73 switch (elembt) {
74 case T_LONG: return ciConstant(tary->long_at(index));
75 case T_FLOAT: return ciConstant(tary->float_at(index));
76 case T_DOUBLE: return ciConstant(tary->double_at(index));
77 default: return ciConstant();
78 case T_BYTE: value = tary->byte_at(index); break;
79 case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
80 case T_SHORT: value = tary->short_at(index); break;
81 case T_CHAR: value = tary->char_at(index); break;
82 case T_INT: value = tary->int_at(index); break;
83 }
84 return ciConstant(elembt, value);
85 }
86
87 // ------------------------------------------------------------------
88 // ciArray::element_value
|
1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
49 return ciConstant();
50 assert(ary->is_array(), "");
51 if (index < 0 || index >= ary->length())
52 return ciConstant();
53 ArrayKlass* ak = (ArrayKlass*) ary->klass();
54 BasicType abt = ak->element_type();
55 if (fixup_element_type(elembt) !=
56 fixup_element_type(abt))
57 return ciConstant();
58 switch (elembt) {
59 case T_ARRAY:
60 case T_OBJECT:
61 {
62 assert(ary->is_objArray(), "");
63 objArrayOop objary = (objArrayOop) ary;
64 oop elem = objary->obj_at(index);
65 ciEnv* env = CURRENT_ENV;
66 ciObject* box = env->get_object(elem);
67 return ciConstant(T_OBJECT, box);
68 }
69 default:
70 break;
71 }
72 assert(ary->is_typeArray(), "");
73 typeArrayOop tary = (typeArrayOop) ary;
74 jint value = 0;
75 switch (elembt) {
76 case T_LONG: return ciConstant(tary->long_at(index));
77 case T_FLOAT: return ciConstant(tary->float_at(index));
78 case T_DOUBLE: return ciConstant(tary->double_at(index));
79 default: return ciConstant();
80 case T_BYTE: value = tary->byte_at(index); break;
81 case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
82 case T_SHORT: value = tary->short_at(index); break;
83 case T_CHAR: value = tary->char_at(index); break;
84 case T_INT: value = tary->int_at(index); break;
85 }
86 return ciConstant(elembt, value);
87 }
88
89 // ------------------------------------------------------------------
90 // ciArray::element_value
|