Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciArray.cpp
32285 views
/*1* Copyright (c) 1999, 2013, 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.hpp"30#include "oops/objArrayOop.hpp"31#include "oops/typeArrayOop.hpp"3233// ciArray34//35// This class represents an arrayOop in the HotSpot virtual36// machine.37static BasicType fixup_element_type(BasicType bt) {38if (bt == T_ARRAY) return T_OBJECT;39if (bt == T_BOOLEAN) return T_BYTE;40return bt;41}4243ciConstant ciArray::element_value_impl(BasicType elembt,44arrayOop ary,45int index) {46if (ary == NULL)47return ciConstant();48assert(ary->is_array(), "");49if (index < 0 || index >= ary->length())50return ciConstant();51ArrayKlass* ak = (ArrayKlass*) ary->klass();52BasicType abt = ak->element_type();53if (fixup_element_type(elembt) !=54fixup_element_type(abt))55return ciConstant();56switch (elembt) {57case T_ARRAY:58case T_OBJECT:59{60assert(ary->is_objArray(), "");61objArrayOop objary = (objArrayOop) ary;62oop elem = objary->obj_at(index);63ciEnv* env = CURRENT_ENV;64ciObject* box = env->get_object(elem);65return ciConstant(T_OBJECT, box);66}67}68assert(ary->is_typeArray(), "");69typeArrayOop tary = (typeArrayOop) ary;70jint value = 0;71switch (elembt) {72case T_LONG: return ciConstant(tary->long_at(index));73case T_FLOAT: return ciConstant(tary->float_at(index));74case T_DOUBLE: return ciConstant(tary->double_at(index));75default: return ciConstant();76case T_BYTE: value = tary->byte_at(index); break;77case T_BOOLEAN: value = tary->byte_at(index) & 1; break;78case T_SHORT: value = tary->short_at(index); break;79case T_CHAR: value = tary->char_at(index); break;80case T_INT: value = tary->int_at(index); break;81}82return ciConstant(elembt, value);83}8485// ------------------------------------------------------------------86// ciArray::element_value87//88// Current value of an element.89// Returns T_ILLEGAL if there is no element at the given index.90ciConstant ciArray::element_value(int index) {91BasicType elembt = element_basic_type();92GUARDED_VM_ENTRY(93return element_value_impl(elembt, get_arrayOop(), index);94)95}9697// ------------------------------------------------------------------98// ciArray::element_value_by_offset99//100// Current value of an element at the specified offset.101// Returns T_ILLEGAL if there is no element at the given offset.102ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {103BasicType elembt = element_basic_type();104intptr_t shift = exact_log2(type2aelembytes(elembt));105intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);106intptr_t index = (element_offset - header) >> shift;107intptr_t offset = header + ((intptr_t)index << shift);108if (offset != element_offset || index != (jint)index)109return ciConstant();110return element_value((jint) index);111}112113// ------------------------------------------------------------------114// ciArray::print_impl115//116// Implementation of the print method.117void ciArray::print_impl(outputStream* st) {118st->print(" length=%d type=", length());119klass()->print(st);120}121122123