src/share/vm/ci/ciArray.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/ciArray.hpp"
aoqi@0 27 #include "ci/ciArrayKlass.hpp"
aoqi@0 28 #include "ci/ciConstant.hpp"
aoqi@0 29 #include "ci/ciKlass.hpp"
aoqi@0 30 #include "ci/ciUtilities.hpp"
aoqi@0 31 #include "oops/objArrayOop.hpp"
aoqi@0 32 #include "oops/typeArrayOop.hpp"
aoqi@0 33
aoqi@0 34 // ciArray
aoqi@0 35 //
aoqi@0 36 // This class represents an arrayOop in the HotSpot virtual
aoqi@0 37 // machine.
aoqi@0 38 static BasicType fixup_element_type(BasicType bt) {
aoqi@0 39 if (bt == T_ARRAY) return T_OBJECT;
aoqi@0 40 if (bt == T_BOOLEAN) return T_BYTE;
aoqi@0 41 return bt;
aoqi@0 42 }
aoqi@0 43
aoqi@0 44 ciConstant ciArray::element_value_impl(BasicType elembt,
aoqi@0 45 arrayOop ary,
aoqi@0 46 int index) {
aoqi@0 47 if (ary == NULL)
aoqi@0 48 return ciConstant();
aoqi@0 49 assert(ary->is_array(), "");
aoqi@0 50 if (index < 0 || index >= ary->length())
aoqi@0 51 return ciConstant();
aoqi@0 52 ArrayKlass* ak = (ArrayKlass*) ary->klass();
aoqi@0 53 BasicType abt = ak->element_type();
aoqi@0 54 if (fixup_element_type(elembt) !=
aoqi@0 55 fixup_element_type(abt))
aoqi@0 56 return ciConstant();
aoqi@0 57 switch (elembt) {
aoqi@0 58 case T_ARRAY:
aoqi@0 59 case T_OBJECT:
aoqi@0 60 {
aoqi@0 61 assert(ary->is_objArray(), "");
aoqi@0 62 objArrayOop objary = (objArrayOop) ary;
aoqi@0 63 oop elem = objary->obj_at(index);
aoqi@0 64 ciEnv* env = CURRENT_ENV;
aoqi@0 65 ciObject* box = env->get_object(elem);
aoqi@0 66 return ciConstant(T_OBJECT, box);
aoqi@0 67 }
aoqi@0 68 }
aoqi@0 69 assert(ary->is_typeArray(), "");
aoqi@0 70 typeArrayOop tary = (typeArrayOop) ary;
aoqi@0 71 jint value = 0;
aoqi@0 72 switch (elembt) {
aoqi@0 73 case T_LONG: return ciConstant(tary->long_at(index));
aoqi@0 74 case T_FLOAT: return ciConstant(tary->float_at(index));
aoqi@0 75 case T_DOUBLE: return ciConstant(tary->double_at(index));
aoqi@0 76 default: return ciConstant();
aoqi@0 77 case T_BYTE: value = tary->byte_at(index); break;
aoqi@0 78 case T_BOOLEAN: value = tary->byte_at(index) & 1; break;
aoqi@0 79 case T_SHORT: value = tary->short_at(index); break;
aoqi@0 80 case T_CHAR: value = tary->char_at(index); break;
aoqi@0 81 case T_INT: value = tary->int_at(index); break;
aoqi@0 82 }
aoqi@0 83 return ciConstant(elembt, value);
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 // ------------------------------------------------------------------
aoqi@0 87 // ciArray::element_value
aoqi@0 88 //
aoqi@0 89 // Current value of an element.
aoqi@0 90 // Returns T_ILLEGAL if there is no element at the given index.
aoqi@0 91 ciConstant ciArray::element_value(int index) {
aoqi@0 92 BasicType elembt = element_basic_type();
aoqi@0 93 GUARDED_VM_ENTRY(
aoqi@0 94 return element_value_impl(elembt, get_arrayOop(), index);
aoqi@0 95 )
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 // ------------------------------------------------------------------
aoqi@0 99 // ciArray::element_value_by_offset
aoqi@0 100 //
aoqi@0 101 // Current value of an element at the specified offset.
aoqi@0 102 // Returns T_ILLEGAL if there is no element at the given offset.
aoqi@0 103 ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
aoqi@0 104 BasicType elembt = element_basic_type();
aoqi@0 105 intptr_t shift = exact_log2(type2aelembytes(elembt));
aoqi@0 106 intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
aoqi@0 107 intptr_t index = (element_offset - header) >> shift;
aoqi@0 108 intptr_t offset = header + ((intptr_t)index << shift);
aoqi@0 109 if (offset != element_offset || index != (jint)index)
aoqi@0 110 return ciConstant();
aoqi@0 111 return element_value((jint) index);
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 // ------------------------------------------------------------------
aoqi@0 115 // ciArray::print_impl
aoqi@0 116 //
aoqi@0 117 // Implementation of the print method.
aoqi@0 118 void ciArray::print_impl(outputStream* st) {
aoqi@0 119 st->print(" length=%d type=", length());
aoqi@0 120 klass()->print(st);
aoqi@0 121 }

mercurial