Tue, 27 Nov 2012 12:48:52 -0800
8003868: fix shark for latest HotSpot and LLVM
Reviewed-by: twisti
Contributed-by: Roman Kennke <rkennke@redhat.com>
twisti@2047 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
twisti@2047 | 3 | * Copyright 2009 Red Hat, Inc. |
twisti@2047 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
twisti@2047 | 5 | * |
twisti@2047 | 6 | * This code is free software; you can redistribute it and/or modify it |
twisti@2047 | 7 | * under the terms of the GNU General Public License version 2 only, as |
twisti@2047 | 8 | * published by the Free Software Foundation. |
twisti@2047 | 9 | * |
twisti@2047 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
twisti@2047 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
twisti@2047 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
twisti@2047 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
twisti@2047 | 14 | * accompanied this code). |
twisti@2047 | 15 | * |
twisti@2047 | 16 | * You should have received a copy of the GNU General Public License version |
twisti@2047 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
twisti@2047 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
twisti@2047 | 19 | * |
twisti@2047 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
twisti@2047 | 21 | * or visit www.oracle.com if you need additional information or have any |
twisti@2047 | 22 | * questions. |
twisti@2047 | 23 | * |
twisti@2047 | 24 | */ |
twisti@2047 | 25 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
stefank@2314 | 27 | #include "ci/ciInstance.hpp" |
stefank@2314 | 28 | #include "ci/ciStreams.hpp" |
stefank@2314 | 29 | #include "shark/sharkBuilder.hpp" |
stefank@2314 | 30 | #include "shark/sharkConstant.hpp" |
stefank@2314 | 31 | #include "shark/sharkValue.hpp" |
twisti@2047 | 32 | |
twisti@2047 | 33 | using namespace llvm; |
twisti@2047 | 34 | |
twisti@2047 | 35 | SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) { |
twisti@2047 | 36 | ciConstant constant = iter->get_constant(); |
twisti@2047 | 37 | ciType *type = NULL; |
twisti@2047 | 38 | if (constant.basic_type() == T_OBJECT) { |
twisti@2047 | 39 | ciEnv *env = ciEnv::current(); |
twisti@4314 | 40 | assert(constant.as_object()->klass() == env->String_klass() || constant.as_object()->klass() == env->Class_klass(), "should be"); |
twisti@4314 | 41 | type = constant.as_object()->klass(); |
twisti@2047 | 42 | } |
twisti@2047 | 43 | return new SharkConstant(constant, type); |
twisti@2047 | 44 | } |
twisti@2047 | 45 | |
twisti@2047 | 46 | SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) { |
twisti@2047 | 47 | bool will_link; |
twisti@2047 | 48 | ciField *field = iter->get_field(will_link); |
twisti@2047 | 49 | assert(will_link, "typeflow responsibility"); |
twisti@2047 | 50 | |
twisti@2047 | 51 | return new SharkConstant(field->constant_value(), field->type()); |
twisti@2047 | 52 | } |
twisti@2047 | 53 | |
twisti@2047 | 54 | SharkConstant::SharkConstant(ciConstant constant, ciType *type) { |
twisti@2047 | 55 | SharkValue *value = NULL; |
twisti@2047 | 56 | |
twisti@2047 | 57 | switch (constant.basic_type()) { |
twisti@2047 | 58 | case T_BOOLEAN: |
twisti@2047 | 59 | case T_BYTE: |
twisti@2047 | 60 | case T_CHAR: |
twisti@2047 | 61 | case T_SHORT: |
twisti@2047 | 62 | case T_INT: |
twisti@2047 | 63 | value = SharkValue::jint_constant(constant.as_int()); |
twisti@2047 | 64 | break; |
twisti@2047 | 65 | |
twisti@2047 | 66 | case T_LONG: |
twisti@2047 | 67 | value = SharkValue::jlong_constant(constant.as_long()); |
twisti@2047 | 68 | break; |
twisti@2047 | 69 | |
twisti@2047 | 70 | case T_FLOAT: |
twisti@2047 | 71 | value = SharkValue::jfloat_constant(constant.as_float()); |
twisti@2047 | 72 | break; |
twisti@2047 | 73 | |
twisti@2047 | 74 | case T_DOUBLE: |
twisti@2047 | 75 | value = SharkValue::jdouble_constant(constant.as_double()); |
twisti@2047 | 76 | break; |
twisti@2047 | 77 | |
twisti@2047 | 78 | case T_OBJECT: |
twisti@2047 | 79 | case T_ARRAY: |
twisti@2047 | 80 | break; |
twisti@2047 | 81 | |
twisti@2047 | 82 | case T_ILLEGAL: |
twisti@2047 | 83 | // out of memory |
twisti@2047 | 84 | _is_loaded = false; |
twisti@2047 | 85 | return; |
twisti@2047 | 86 | |
twisti@2047 | 87 | default: |
twisti@2047 | 88 | tty->print_cr("Unhandled type %s", type2name(constant.basic_type())); |
twisti@2047 | 89 | ShouldNotReachHere(); |
twisti@2047 | 90 | } |
twisti@2047 | 91 | |
twisti@2047 | 92 | // Handle primitive types. We create SharkValues for these |
twisti@2047 | 93 | // now; doing so doesn't emit any code, and it allows us to |
twisti@2047 | 94 | // delegate a bunch of stuff to the SharkValue code. |
twisti@2047 | 95 | if (value) { |
twisti@2047 | 96 | _value = value; |
twisti@2047 | 97 | _is_loaded = true; |
twisti@2047 | 98 | _is_nonzero = value->zero_checked(); |
twisti@2047 | 99 | _is_two_word = value->is_two_word(); |
twisti@2047 | 100 | return; |
twisti@2047 | 101 | } |
twisti@2047 | 102 | |
twisti@2047 | 103 | // Handle reference types. This is tricky because some |
twisti@2047 | 104 | // ciObjects are psuedo-objects that refer to oops which |
twisti@2047 | 105 | // have yet to be created. We need to spot the unloaded |
twisti@2047 | 106 | // objects (which differ between ldc* and get*, thanks!) |
twisti@2047 | 107 | ciObject *object = constant.as_object(); |
twisti@2047 | 108 | assert(type != NULL, "shouldn't be"); |
twisti@4314 | 109 | |
twisti@4314 | 110 | if ((! object->is_null_object()) && object->klass() == ciEnv::current()->Class_klass()) { |
twisti@4314 | 111 | ciKlass *klass = object->klass(); |
twisti@4314 | 112 | if (! klass->is_loaded()) { |
twisti@2047 | 113 | _is_loaded = false; |
twisti@2047 | 114 | return; |
twisti@2047 | 115 | } |
twisti@2047 | 116 | } |
twisti@4314 | 117 | |
twisti@4314 | 118 | if (object->is_null_object() || ! object->can_be_constant() || ! object->is_loaded()) { |
twisti@2047 | 119 | _is_loaded = false; |
twisti@2047 | 120 | return; |
twisti@2047 | 121 | } |
twisti@2047 | 122 | |
twisti@2047 | 123 | _value = NULL; |
twisti@2047 | 124 | _object = object; |
twisti@2047 | 125 | _type = type; |
twisti@2047 | 126 | _is_loaded = true; |
twisti@2047 | 127 | _is_nonzero = true; |
twisti@2047 | 128 | _is_two_word = false; |
twisti@2047 | 129 | } |