src/share/vm/ci/ciArray.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciArray.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,121 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "ci/ciArray.hpp"
    1.30 +#include "ci/ciArrayKlass.hpp"
    1.31 +#include "ci/ciConstant.hpp"
    1.32 +#include "ci/ciKlass.hpp"
    1.33 +#include "ci/ciUtilities.hpp"
    1.34 +#include "oops/objArrayOop.hpp"
    1.35 +#include "oops/typeArrayOop.hpp"
    1.36 +
    1.37 +// ciArray
    1.38 +//
    1.39 +// This class represents an arrayOop in the HotSpot virtual
    1.40 +// machine.
    1.41 +static BasicType fixup_element_type(BasicType bt) {
    1.42 +  if (bt == T_ARRAY)    return T_OBJECT;
    1.43 +  if (bt == T_BOOLEAN)  return T_BYTE;
    1.44 +  return bt;
    1.45 +}
    1.46 +
    1.47 +ciConstant ciArray::element_value_impl(BasicType elembt,
    1.48 +                                       arrayOop ary,
    1.49 +                                       int index) {
    1.50 +  if (ary == NULL)
    1.51 +    return ciConstant();
    1.52 +  assert(ary->is_array(), "");
    1.53 +  if (index < 0 || index >= ary->length())
    1.54 +    return ciConstant();
    1.55 +  ArrayKlass* ak = (ArrayKlass*) ary->klass();
    1.56 +  BasicType abt = ak->element_type();
    1.57 +  if (fixup_element_type(elembt) !=
    1.58 +      fixup_element_type(abt))
    1.59 +    return ciConstant();
    1.60 +  switch (elembt) {
    1.61 +  case T_ARRAY:
    1.62 +  case T_OBJECT:
    1.63 +    {
    1.64 +      assert(ary->is_objArray(), "");
    1.65 +      objArrayOop objary = (objArrayOop) ary;
    1.66 +      oop elem = objary->obj_at(index);
    1.67 +      ciEnv* env = CURRENT_ENV;
    1.68 +      ciObject* box = env->get_object(elem);
    1.69 +      return ciConstant(T_OBJECT, box);
    1.70 +    }
    1.71 +  }
    1.72 +  assert(ary->is_typeArray(), "");
    1.73 +  typeArrayOop tary = (typeArrayOop) ary;
    1.74 +  jint value = 0;
    1.75 +  switch (elembt) {
    1.76 +  case T_LONG:          return ciConstant(tary->long_at(index));
    1.77 +  case T_FLOAT:         return ciConstant(tary->float_at(index));
    1.78 +  case T_DOUBLE:        return ciConstant(tary->double_at(index));
    1.79 +  default:              return ciConstant();
    1.80 +  case T_BYTE:          value = tary->byte_at(index);           break;
    1.81 +  case T_BOOLEAN:       value = tary->byte_at(index) & 1;       break;
    1.82 +  case T_SHORT:         value = tary->short_at(index);          break;
    1.83 +  case T_CHAR:          value = tary->char_at(index);           break;
    1.84 +  case T_INT:           value = tary->int_at(index);            break;
    1.85 +  }
    1.86 +  return ciConstant(elembt, value);
    1.87 +}
    1.88 +
    1.89 +// ------------------------------------------------------------------
    1.90 +// ciArray::element_value
    1.91 +//
    1.92 +// Current value of an element.
    1.93 +// Returns T_ILLEGAL if there is no element at the given index.
    1.94 +ciConstant ciArray::element_value(int index) {
    1.95 +  BasicType elembt = element_basic_type();
    1.96 +  GUARDED_VM_ENTRY(
    1.97 +    return element_value_impl(elembt, get_arrayOop(), index);
    1.98 +  )
    1.99 +}
   1.100 +
   1.101 +// ------------------------------------------------------------------
   1.102 +// ciArray::element_value_by_offset
   1.103 +//
   1.104 +// Current value of an element at the specified offset.
   1.105 +// Returns T_ILLEGAL if there is no element at the given offset.
   1.106 +ciConstant ciArray::element_value_by_offset(intptr_t element_offset) {
   1.107 +  BasicType elembt = element_basic_type();
   1.108 +  intptr_t shift  = exact_log2(type2aelembytes(elembt));
   1.109 +  intptr_t header = arrayOopDesc::base_offset_in_bytes(elembt);
   1.110 +  intptr_t index = (element_offset - header) >> shift;
   1.111 +  intptr_t offset = header + ((intptr_t)index << shift);
   1.112 +  if (offset != element_offset || index != (jint)index)
   1.113 +    return ciConstant();
   1.114 +  return element_value((jint) index);
   1.115 +}
   1.116 +
   1.117 +// ------------------------------------------------------------------
   1.118 +// ciArray::print_impl
   1.119 +//
   1.120 +// Implementation of the print method.
   1.121 +void ciArray::print_impl(outputStream* st) {
   1.122 +  st->print(" length=%d type=", length());
   1.123 +  klass()->print(st);
   1.124 +}

mercurial