Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkConstant.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2009 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "ci/ciInstance.hpp"27#include "ci/ciStreams.hpp"28#include "shark/sharkBuilder.hpp"29#include "shark/sharkConstant.hpp"30#include "shark/sharkValue.hpp"3132using namespace llvm;3334SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) {35ciConstant constant = iter->get_constant();36ciType *type = NULL;37if (constant.basic_type() == T_OBJECT) {38ciEnv *env = ciEnv::current();3940assert(constant.as_object()->klass() == env->String_klass()41|| constant.as_object()->klass() == env->Class_klass()42|| constant.as_object()->klass()->is_subtype_of(env->MethodType_klass())43|| constant.as_object()->klass()->is_subtype_of(env->MethodHandle_klass()), "should be");4445type = constant.as_object()->klass();46}47return new SharkConstant(constant, type);48}4950SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) {51bool will_link;52ciField *field = iter->get_field(will_link);53assert(will_link, "typeflow responsibility");5455return new SharkConstant(field->constant_value(), field->type());56}5758SharkConstant::SharkConstant(ciConstant constant, ciType *type) {59SharkValue *value = NULL;6061switch (constant.basic_type()) {62case T_BOOLEAN:63case T_BYTE:64case T_CHAR:65case T_SHORT:66case T_INT:67value = SharkValue::jint_constant(constant.as_int());68break;6970case T_LONG:71value = SharkValue::jlong_constant(constant.as_long());72break;7374case T_FLOAT:75value = SharkValue::jfloat_constant(constant.as_float());76break;7778case T_DOUBLE:79value = SharkValue::jdouble_constant(constant.as_double());80break;8182case T_OBJECT:83case T_ARRAY:84break;8586case T_ILLEGAL:87// out of memory88_is_loaded = false;89return;9091default:92tty->print_cr("Unhandled type %s", type2name(constant.basic_type()));93ShouldNotReachHere();94}9596// Handle primitive types. We create SharkValues for these97// now; doing so doesn't emit any code, and it allows us to98// delegate a bunch of stuff to the SharkValue code.99if (value) {100_value = value;101_is_loaded = true;102_is_nonzero = value->zero_checked();103_is_two_word = value->is_two_word();104return;105}106107// Handle reference types. This is tricky because some108// ciObjects are psuedo-objects that refer to oops which109// have yet to be created. We need to spot the unloaded110// objects (which differ between ldc* and get*, thanks!)111ciObject *object = constant.as_object();112assert(type != NULL, "shouldn't be");113114if ((! object->is_null_object()) && object->klass() == ciEnv::current()->Class_klass()) {115ciKlass *klass = object->klass();116if (! klass->is_loaded()) {117_is_loaded = false;118return;119}120}121122if (object->is_null_object() || ! object->can_be_constant() || ! object->is_loaded()) {123_is_loaded = false;124return;125}126127_value = NULL;128_object = object;129_type = type;130_is_loaded = true;131_is_nonzero = true;132_is_two_word = false;133}134135136