src/share/vm/ci/ciArray.cpp

Wed, 23 Oct 2013 12:40:23 +0200

author
roland
date
Wed, 23 Oct 2013 12:40:23 +0200
changeset 5991
b2ee5dc63353
parent 5658
edb5ab0f3fe5
child 6198
55fb97c4c58d
permissions
-rw-r--r--

8024070: C2 needs some form of type speculation
Summary: record unused type profile information with type system, propagate and use it.
Reviewed-by: kvn, twisti

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

mercurial