twisti@2047: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. twisti@2047: * Copyright 2009 Red Hat, Inc. twisti@2047: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@2047: * twisti@2047: * This code is free software; you can redistribute it and/or modify it twisti@2047: * under the terms of the GNU General Public License version 2 only, as twisti@2047: * published by the Free Software Foundation. twisti@2047: * twisti@2047: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@2047: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@2047: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@2047: * version 2 for more details (a copy is included in the LICENSE file that twisti@2047: * accompanied this code). twisti@2047: * twisti@2047: * You should have received a copy of the GNU General Public License version twisti@2047: * 2 along with this work; if not, write to the Free Software Foundation, twisti@2047: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@2047: * twisti@2047: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA twisti@2047: * or visit www.oracle.com if you need additional information or have any twisti@2047: * questions. twisti@2047: * twisti@2047: */ twisti@2047: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "ci/ciInstance.hpp" stefank@2314: #include "ci/ciStreams.hpp" stefank@2314: #include "shark/sharkBuilder.hpp" stefank@2314: #include "shark/sharkConstant.hpp" stefank@2314: #include "shark/sharkValue.hpp" twisti@2047: twisti@2047: using namespace llvm; twisti@2047: twisti@2047: SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) { twisti@2047: ciConstant constant = iter->get_constant(); twisti@2047: ciType *type = NULL; twisti@2047: if (constant.basic_type() == T_OBJECT) { twisti@2047: ciEnv *env = ciEnv::current(); twisti@4444: twisti@4444: assert(constant.as_object()->klass() == env->String_klass() twisti@4444: || constant.as_object()->klass() == env->Class_klass() twisti@4444: || constant.as_object()->klass()->is_subtype_of(env->MethodType_klass()) twisti@4444: || constant.as_object()->klass()->is_subtype_of(env->MethodHandle_klass()), "should be"); twisti@4444: twisti@4314: type = constant.as_object()->klass(); twisti@2047: } twisti@2047: return new SharkConstant(constant, type); twisti@2047: } twisti@2047: twisti@2047: SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) { twisti@2047: bool will_link; twisti@2047: ciField *field = iter->get_field(will_link); twisti@2047: assert(will_link, "typeflow responsibility"); twisti@2047: twisti@2047: return new SharkConstant(field->constant_value(), field->type()); twisti@2047: } twisti@2047: twisti@2047: SharkConstant::SharkConstant(ciConstant constant, ciType *type) { twisti@2047: SharkValue *value = NULL; twisti@2047: twisti@2047: switch (constant.basic_type()) { twisti@2047: case T_BOOLEAN: twisti@2047: case T_BYTE: twisti@2047: case T_CHAR: twisti@2047: case T_SHORT: twisti@2047: case T_INT: twisti@2047: value = SharkValue::jint_constant(constant.as_int()); twisti@2047: break; twisti@2047: twisti@2047: case T_LONG: twisti@2047: value = SharkValue::jlong_constant(constant.as_long()); twisti@2047: break; twisti@2047: twisti@2047: case T_FLOAT: twisti@2047: value = SharkValue::jfloat_constant(constant.as_float()); twisti@2047: break; twisti@2047: twisti@2047: case T_DOUBLE: twisti@2047: value = SharkValue::jdouble_constant(constant.as_double()); twisti@2047: break; twisti@2047: twisti@2047: case T_OBJECT: twisti@2047: case T_ARRAY: twisti@2047: break; twisti@2047: twisti@2047: case T_ILLEGAL: twisti@2047: // out of memory twisti@2047: _is_loaded = false; twisti@2047: return; twisti@2047: twisti@2047: default: twisti@2047: tty->print_cr("Unhandled type %s", type2name(constant.basic_type())); twisti@2047: ShouldNotReachHere(); twisti@2047: } twisti@2047: twisti@2047: // Handle primitive types. We create SharkValues for these twisti@2047: // now; doing so doesn't emit any code, and it allows us to twisti@2047: // delegate a bunch of stuff to the SharkValue code. twisti@2047: if (value) { twisti@2047: _value = value; twisti@2047: _is_loaded = true; twisti@2047: _is_nonzero = value->zero_checked(); twisti@2047: _is_two_word = value->is_two_word(); twisti@2047: return; twisti@2047: } twisti@2047: twisti@2047: // Handle reference types. This is tricky because some twisti@2047: // ciObjects are psuedo-objects that refer to oops which twisti@2047: // have yet to be created. We need to spot the unloaded twisti@2047: // objects (which differ between ldc* and get*, thanks!) twisti@2047: ciObject *object = constant.as_object(); twisti@2047: assert(type != NULL, "shouldn't be"); twisti@4314: twisti@4314: if ((! object->is_null_object()) && object->klass() == ciEnv::current()->Class_klass()) { twisti@4314: ciKlass *klass = object->klass(); twisti@4314: if (! klass->is_loaded()) { twisti@2047: _is_loaded = false; twisti@2047: return; twisti@2047: } twisti@2047: } twisti@4314: twisti@4314: if (object->is_null_object() || ! object->can_be_constant() || ! object->is_loaded()) { twisti@2047: _is_loaded = false; twisti@2047: return; twisti@2047: } twisti@2047: twisti@2047: _value = NULL; twisti@2047: _object = object; twisti@2047: _type = type; twisti@2047: _is_loaded = true; twisti@2047: _is_nonzero = true; twisti@2047: _is_two_word = false; twisti@2047: }