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