Wed, 11 Aug 2010 05:51:21 -0700
6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>
twisti@2047 | 1 | /* |
twisti@2047 | 2 | * Copyright (c) 1999, 2007, 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 | |
twisti@2047 | 26 | #include "incls/_precompiled.incl" |
twisti@2047 | 27 | #include "incls/_sharkConstant.cpp.incl" |
twisti@2047 | 28 | |
twisti@2047 | 29 | using namespace llvm; |
twisti@2047 | 30 | |
twisti@2047 | 31 | SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) { |
twisti@2047 | 32 | ciConstant constant = iter->get_constant(); |
twisti@2047 | 33 | ciType *type = NULL; |
twisti@2047 | 34 | if (constant.basic_type() == T_OBJECT) { |
twisti@2047 | 35 | ciEnv *env = ciEnv::current(); |
twisti@2047 | 36 | if (constant.as_object()->is_klass()) |
twisti@2047 | 37 | type = env->Class_klass(); |
twisti@2047 | 38 | else |
twisti@2047 | 39 | type = env->String_klass(); |
twisti@2047 | 40 | } |
twisti@2047 | 41 | return new SharkConstant(constant, type); |
twisti@2047 | 42 | } |
twisti@2047 | 43 | |
twisti@2047 | 44 | SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) { |
twisti@2047 | 45 | bool will_link; |
twisti@2047 | 46 | ciField *field = iter->get_field(will_link); |
twisti@2047 | 47 | assert(will_link, "typeflow responsibility"); |
twisti@2047 | 48 | |
twisti@2047 | 49 | return new SharkConstant(field->constant_value(), field->type()); |
twisti@2047 | 50 | } |
twisti@2047 | 51 | |
twisti@2047 | 52 | SharkConstant::SharkConstant(ciConstant constant, ciType *type) { |
twisti@2047 | 53 | SharkValue *value = NULL; |
twisti@2047 | 54 | |
twisti@2047 | 55 | switch (constant.basic_type()) { |
twisti@2047 | 56 | case T_BOOLEAN: |
twisti@2047 | 57 | case T_BYTE: |
twisti@2047 | 58 | case T_CHAR: |
twisti@2047 | 59 | case T_SHORT: |
twisti@2047 | 60 | case T_INT: |
twisti@2047 | 61 | value = SharkValue::jint_constant(constant.as_int()); |
twisti@2047 | 62 | break; |
twisti@2047 | 63 | |
twisti@2047 | 64 | case T_LONG: |
twisti@2047 | 65 | value = SharkValue::jlong_constant(constant.as_long()); |
twisti@2047 | 66 | break; |
twisti@2047 | 67 | |
twisti@2047 | 68 | case T_FLOAT: |
twisti@2047 | 69 | value = SharkValue::jfloat_constant(constant.as_float()); |
twisti@2047 | 70 | break; |
twisti@2047 | 71 | |
twisti@2047 | 72 | case T_DOUBLE: |
twisti@2047 | 73 | value = SharkValue::jdouble_constant(constant.as_double()); |
twisti@2047 | 74 | break; |
twisti@2047 | 75 | |
twisti@2047 | 76 | case T_OBJECT: |
twisti@2047 | 77 | case T_ARRAY: |
twisti@2047 | 78 | break; |
twisti@2047 | 79 | |
twisti@2047 | 80 | case T_ILLEGAL: |
twisti@2047 | 81 | // out of memory |
twisti@2047 | 82 | _is_loaded = false; |
twisti@2047 | 83 | return; |
twisti@2047 | 84 | |
twisti@2047 | 85 | default: |
twisti@2047 | 86 | tty->print_cr("Unhandled type %s", type2name(constant.basic_type())); |
twisti@2047 | 87 | ShouldNotReachHere(); |
twisti@2047 | 88 | } |
twisti@2047 | 89 | |
twisti@2047 | 90 | // Handle primitive types. We create SharkValues for these |
twisti@2047 | 91 | // now; doing so doesn't emit any code, and it allows us to |
twisti@2047 | 92 | // delegate a bunch of stuff to the SharkValue code. |
twisti@2047 | 93 | if (value) { |
twisti@2047 | 94 | _value = value; |
twisti@2047 | 95 | _is_loaded = true; |
twisti@2047 | 96 | _is_nonzero = value->zero_checked(); |
twisti@2047 | 97 | _is_two_word = value->is_two_word(); |
twisti@2047 | 98 | return; |
twisti@2047 | 99 | } |
twisti@2047 | 100 | |
twisti@2047 | 101 | // Handle reference types. This is tricky because some |
twisti@2047 | 102 | // ciObjects are psuedo-objects that refer to oops which |
twisti@2047 | 103 | // have yet to be created. We need to spot the unloaded |
twisti@2047 | 104 | // objects (which differ between ldc* and get*, thanks!) |
twisti@2047 | 105 | ciObject *object = constant.as_object(); |
twisti@2047 | 106 | assert(type != NULL, "shouldn't be"); |
twisti@2047 | 107 | if (object->is_klass()) { |
twisti@2047 | 108 | // The constant returned for a klass is the ciKlass |
twisti@2047 | 109 | // for the entry, but we want the java_mirror. |
twisti@2047 | 110 | ciKlass *klass = object->as_klass(); |
twisti@2047 | 111 | if (!klass->is_loaded()) { |
twisti@2047 | 112 | _is_loaded = false; |
twisti@2047 | 113 | return; |
twisti@2047 | 114 | } |
twisti@2047 | 115 | object = klass->java_mirror(); |
twisti@2047 | 116 | } |
twisti@2047 | 117 | if (object->is_null_object() || !object->can_be_constant()) { |
twisti@2047 | 118 | _is_loaded = false; |
twisti@2047 | 119 | return; |
twisti@2047 | 120 | } |
twisti@2047 | 121 | |
twisti@2047 | 122 | _value = NULL; |
twisti@2047 | 123 | _object = object; |
twisti@2047 | 124 | _type = type; |
twisti@2047 | 125 | _is_loaded = true; |
twisti@2047 | 126 | _is_nonzero = true; |
twisti@2047 | 127 | _is_two_word = false; |
twisti@2047 | 128 | } |