1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkValue.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,264 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "precompiled.hpp" 1.30 +#include "ci/ciType.hpp" 1.31 +#include "shark/llvmHeaders.hpp" 1.32 +#include "shark/llvmValue.hpp" 1.33 +#include "shark/sharkBuilder.hpp" 1.34 +#include "shark/sharkValue.hpp" 1.35 + 1.36 +using namespace llvm; 1.37 + 1.38 +// Cloning 1.39 + 1.40 +SharkValue* SharkNormalValue::clone() const { 1.41 + return SharkValue::create_generic(type(), generic_value(), zero_checked()); 1.42 +} 1.43 +SharkValue* SharkPHIValue::clone() const { 1.44 + return SharkValue::create_phi(type(), (PHINode *) generic_value(), this); 1.45 +} 1.46 +SharkValue* SharkAddressValue::clone() const { 1.47 + return SharkValue::address_constant(address_value()); 1.48 +} 1.49 + 1.50 +// Casting 1.51 + 1.52 +bool SharkValue::is_phi() const { 1.53 + return false; 1.54 +} 1.55 +bool SharkPHIValue::is_phi() const { 1.56 + return true; 1.57 +} 1.58 +SharkPHIValue* SharkValue::as_phi() { 1.59 + ShouldNotCallThis(); 1.60 +} 1.61 +SharkPHIValue* SharkPHIValue::as_phi() { 1.62 + return this; 1.63 +} 1.64 + 1.65 +// Comparison 1.66 + 1.67 +bool SharkNormalValue::equal_to(SharkValue *other) const { 1.68 + return (this->type() == other->type() && 1.69 + this->generic_value() == other->generic_value() && 1.70 + this->zero_checked() == other->zero_checked()); 1.71 +} 1.72 +bool SharkAddressValue::equal_to(SharkValue *other) const { 1.73 + return (this->address_value() == other->address_value()); 1.74 +} 1.75 + 1.76 +// Type access 1.77 + 1.78 +ciType* SharkValue::type() const { 1.79 + ShouldNotCallThis(); 1.80 +} 1.81 +ciType* SharkNormalValue::type() const { 1.82 + return _type; 1.83 +} 1.84 + 1.85 +BasicType SharkNormalValue::basic_type() const { 1.86 + return type()->basic_type(); 1.87 +} 1.88 +BasicType SharkAddressValue::basic_type() const { 1.89 + return T_ADDRESS; 1.90 +} 1.91 + 1.92 +int SharkNormalValue::size() const { 1.93 + return type()->size(); 1.94 +} 1.95 +int SharkAddressValue::size() const { 1.96 + return 1; 1.97 +} 1.98 + 1.99 +bool SharkValue::is_jint() const { 1.100 + return false; 1.101 +} 1.102 +bool SharkValue::is_jlong() const { 1.103 + return false; 1.104 +} 1.105 +bool SharkValue::is_jfloat() const { 1.106 + return false; 1.107 +} 1.108 +bool SharkValue::is_jdouble() const { 1.109 + return false; 1.110 +} 1.111 +bool SharkValue::is_jobject() const { 1.112 + return false; 1.113 +} 1.114 +bool SharkValue::is_jarray() const { 1.115 + return false; 1.116 +} 1.117 +bool SharkValue::is_address() const { 1.118 + return false; 1.119 +} 1.120 + 1.121 +bool SharkNormalValue::is_jint() const { 1.122 + return llvm_value()->getType() == SharkType::jint_type(); 1.123 +} 1.124 +bool SharkNormalValue::is_jlong() const { 1.125 + return llvm_value()->getType() == SharkType::jlong_type(); 1.126 +} 1.127 +bool SharkNormalValue::is_jfloat() const { 1.128 + return llvm_value()->getType() == SharkType::jfloat_type(); 1.129 +} 1.130 +bool SharkNormalValue::is_jdouble() const { 1.131 + return llvm_value()->getType() == SharkType::jdouble_type(); 1.132 +} 1.133 +bool SharkNormalValue::is_jobject() const { 1.134 + return llvm_value()->getType() == SharkType::oop_type(); 1.135 +} 1.136 +bool SharkNormalValue::is_jarray() const { 1.137 + return basic_type() == T_ARRAY; 1.138 +} 1.139 +bool SharkAddressValue::is_address() const { 1.140 + return true; 1.141 +} 1.142 + 1.143 +// Typed conversions from SharkValues 1.144 + 1.145 +Value* SharkValue::jint_value() const { 1.146 + ShouldNotCallThis(); 1.147 +} 1.148 +Value* SharkValue::jlong_value() const { 1.149 + ShouldNotCallThis(); 1.150 +} 1.151 +Value* SharkValue::jfloat_value() const { 1.152 + ShouldNotCallThis(); 1.153 +} 1.154 +Value* SharkValue::jdouble_value() const { 1.155 + ShouldNotCallThis(); 1.156 +} 1.157 +Value* SharkValue::jobject_value() const { 1.158 + ShouldNotCallThis(); 1.159 +} 1.160 +Value* SharkValue::jarray_value() const { 1.161 + ShouldNotCallThis(); 1.162 +} 1.163 +int SharkValue::address_value() const { 1.164 + ShouldNotCallThis(); 1.165 +} 1.166 + 1.167 +Value* SharkNormalValue::jint_value() const { 1.168 + assert(is_jint(), "should be"); 1.169 + return llvm_value(); 1.170 +} 1.171 +Value* SharkNormalValue::jlong_value() const { 1.172 + assert(is_jlong(), "should be"); 1.173 + return llvm_value(); 1.174 +} 1.175 +Value* SharkNormalValue::jfloat_value() const { 1.176 + assert(is_jfloat(), "should be"); 1.177 + return llvm_value(); 1.178 +} 1.179 +Value* SharkNormalValue::jdouble_value() const { 1.180 + assert(is_jdouble(), "should be"); 1.181 + return llvm_value(); 1.182 +} 1.183 +Value* SharkNormalValue::jobject_value() const { 1.184 + assert(is_jobject(), "should be"); 1.185 + return llvm_value(); 1.186 +} 1.187 +Value* SharkNormalValue::jarray_value() const { 1.188 + // XXX assert(is_jarray(), "should be"); 1.189 + // XXX http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=324 1.190 + assert(is_jobject(), "should be"); 1.191 + return llvm_value(); 1.192 +} 1.193 +int SharkAddressValue::address_value() const { 1.194 + return _bci; 1.195 +} 1.196 + 1.197 +// Type-losing conversions -- use with care! 1.198 + 1.199 +Value* SharkNormalValue::generic_value() const { 1.200 + return llvm_value(); 1.201 +} 1.202 +Value* SharkAddressValue::generic_value() const { 1.203 + return LLVMValue::intptr_constant(address_value()); 1.204 +} 1.205 + 1.206 +Value* SharkValue::intptr_value(SharkBuilder* builder) const { 1.207 + ShouldNotCallThis(); 1.208 +} 1.209 +Value* SharkNormalValue::intptr_value(SharkBuilder* builder) const { 1.210 + return builder->CreatePtrToInt(jobject_value(), SharkType::intptr_type()); 1.211 +} 1.212 + 1.213 +// Phi-style stuff for SharkPHIState::add_incoming 1.214 + 1.215 +void SharkValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.216 + ShouldNotCallThis(); 1.217 +} 1.218 +void SharkPHIValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.219 + assert(!is_clone(), "shouldn't be"); 1.220 + ((llvm::PHINode *) generic_value())->addIncoming( 1.221 + value->generic_value(), block); 1.222 + if (!value->zero_checked()) 1.223 + _all_incomers_zero_checked = false; 1.224 +} 1.225 +void SharkAddressValue::addIncoming(SharkValue *value, BasicBlock* block) { 1.226 + assert(this->equal_to(value), "should be"); 1.227 +} 1.228 + 1.229 +// Phi-style stuff for SharkState::merge 1.230 + 1.231 +SharkValue* SharkNormalValue::merge(SharkBuilder* builder, 1.232 + SharkValue* other, 1.233 + BasicBlock* other_block, 1.234 + BasicBlock* this_block, 1.235 + const char* name) { 1.236 + assert(type() == other->type(), "should be"); 1.237 + assert(zero_checked() == other->zero_checked(), "should be"); 1.238 + 1.239 + PHINode *phi = builder->CreatePHI(SharkType::to_stackType(type()), 0, name); 1.240 + phi->addIncoming(this->generic_value(), this_block); 1.241 + phi->addIncoming(other->generic_value(), other_block); 1.242 + return SharkValue::create_generic(type(), phi, zero_checked()); 1.243 +} 1.244 +SharkValue* SharkAddressValue::merge(SharkBuilder* builder, 1.245 + SharkValue* other, 1.246 + BasicBlock* other_block, 1.247 + BasicBlock* this_block, 1.248 + const char* name) { 1.249 + assert(this->equal_to(other), "should be"); 1.250 + return this; 1.251 +} 1.252 + 1.253 +// Repeated null and divide-by-zero check removal 1.254 + 1.255 +bool SharkValue::zero_checked() const { 1.256 + ShouldNotCallThis(); 1.257 +} 1.258 +void SharkValue::set_zero_checked(bool zero_checked) { 1.259 + ShouldNotCallThis(); 1.260 +} 1.261 + 1.262 +bool SharkNormalValue::zero_checked() const { 1.263 + return _zero_checked; 1.264 +} 1.265 +void SharkNormalValue::set_zero_checked(bool zero_checked) { 1.266 + _zero_checked = zero_checked; 1.267 +}