src/share/vm/shark/sharkConstant.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2047
d2ede61b7a12
child 4314
2cd5e15048e6
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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@2047 40 if (constant.as_object()->is_klass())
twisti@2047 41 type = env->Class_klass();
twisti@2047 42 else
twisti@2047 43 type = env->String_klass();
twisti@2047 44 }
twisti@2047 45 return new SharkConstant(constant, type);
twisti@2047 46 }
twisti@2047 47
twisti@2047 48 SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) {
twisti@2047 49 bool will_link;
twisti@2047 50 ciField *field = iter->get_field(will_link);
twisti@2047 51 assert(will_link, "typeflow responsibility");
twisti@2047 52
twisti@2047 53 return new SharkConstant(field->constant_value(), field->type());
twisti@2047 54 }
twisti@2047 55
twisti@2047 56 SharkConstant::SharkConstant(ciConstant constant, ciType *type) {
twisti@2047 57 SharkValue *value = NULL;
twisti@2047 58
twisti@2047 59 switch (constant.basic_type()) {
twisti@2047 60 case T_BOOLEAN:
twisti@2047 61 case T_BYTE:
twisti@2047 62 case T_CHAR:
twisti@2047 63 case T_SHORT:
twisti@2047 64 case T_INT:
twisti@2047 65 value = SharkValue::jint_constant(constant.as_int());
twisti@2047 66 break;
twisti@2047 67
twisti@2047 68 case T_LONG:
twisti@2047 69 value = SharkValue::jlong_constant(constant.as_long());
twisti@2047 70 break;
twisti@2047 71
twisti@2047 72 case T_FLOAT:
twisti@2047 73 value = SharkValue::jfloat_constant(constant.as_float());
twisti@2047 74 break;
twisti@2047 75
twisti@2047 76 case T_DOUBLE:
twisti@2047 77 value = SharkValue::jdouble_constant(constant.as_double());
twisti@2047 78 break;
twisti@2047 79
twisti@2047 80 case T_OBJECT:
twisti@2047 81 case T_ARRAY:
twisti@2047 82 break;
twisti@2047 83
twisti@2047 84 case T_ILLEGAL:
twisti@2047 85 // out of memory
twisti@2047 86 _is_loaded = false;
twisti@2047 87 return;
twisti@2047 88
twisti@2047 89 default:
twisti@2047 90 tty->print_cr("Unhandled type %s", type2name(constant.basic_type()));
twisti@2047 91 ShouldNotReachHere();
twisti@2047 92 }
twisti@2047 93
twisti@2047 94 // Handle primitive types. We create SharkValues for these
twisti@2047 95 // now; doing so doesn't emit any code, and it allows us to
twisti@2047 96 // delegate a bunch of stuff to the SharkValue code.
twisti@2047 97 if (value) {
twisti@2047 98 _value = value;
twisti@2047 99 _is_loaded = true;
twisti@2047 100 _is_nonzero = value->zero_checked();
twisti@2047 101 _is_two_word = value->is_two_word();
twisti@2047 102 return;
twisti@2047 103 }
twisti@2047 104
twisti@2047 105 // Handle reference types. This is tricky because some
twisti@2047 106 // ciObjects are psuedo-objects that refer to oops which
twisti@2047 107 // have yet to be created. We need to spot the unloaded
twisti@2047 108 // objects (which differ between ldc* and get*, thanks!)
twisti@2047 109 ciObject *object = constant.as_object();
twisti@2047 110 assert(type != NULL, "shouldn't be");
twisti@2047 111 if (object->is_klass()) {
twisti@2047 112 // The constant returned for a klass is the ciKlass
twisti@2047 113 // for the entry, but we want the java_mirror.
twisti@2047 114 ciKlass *klass = object->as_klass();
twisti@2047 115 if (!klass->is_loaded()) {
twisti@2047 116 _is_loaded = false;
twisti@2047 117 return;
twisti@2047 118 }
twisti@2047 119 object = klass->java_mirror();
twisti@2047 120 }
twisti@2047 121 if (object->is_null_object() || !object->can_be_constant()) {
twisti@2047 122 _is_loaded = false;
twisti@2047 123 return;
twisti@2047 124 }
twisti@2047 125
twisti@2047 126 _value = NULL;
twisti@2047 127 _object = object;
twisti@2047 128 _type = type;
twisti@2047 129 _is_loaded = true;
twisti@2047 130 _is_nonzero = true;
twisti@2047 131 _is_two_word = false;
twisti@2047 132 }

mercurial