src/share/vm/shark/sharkConstant.cpp

Fri, 11 Jan 2013 16:47:23 -0800

author
twisti
date
Fri, 11 Jan 2013 16:47:23 -0800
changeset 4444
606eada1bf86
parent 4314
2cd5e15048e6
child 6198
55fb97c4c58d
permissions
-rw-r--r--

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

mercurial