src/share/vm/shark/sharkState.cpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

twisti@2047 1 /*
twisti@2047 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
twisti@2047 3 * Copyright 2008, 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
twisti@2047 26 #include "incls/_precompiled.incl"
twisti@2047 27 #include "incls/_sharkState.cpp.incl"
twisti@2047 28
twisti@2047 29 using namespace llvm;
twisti@2047 30
twisti@2047 31 void SharkState::initialize(const SharkState *state) {
twisti@2047 32 _locals = NEW_RESOURCE_ARRAY(SharkValue*, max_locals());
twisti@2047 33 _stack = NEW_RESOURCE_ARRAY(SharkValue*, max_stack());
twisti@2047 34
twisti@2047 35 NOT_PRODUCT(memset(_locals, 23, max_locals() * sizeof(SharkValue *)));
twisti@2047 36 NOT_PRODUCT(memset(_stack, 23, max_stack() * sizeof(SharkValue *)));
twisti@2047 37 _sp = _stack;
twisti@2047 38
twisti@2047 39 if (state) {
twisti@2047 40 for (int i = 0; i < max_locals(); i++) {
twisti@2047 41 SharkValue *value = state->local(i);
twisti@2047 42 if (value)
twisti@2047 43 value = value->clone();
twisti@2047 44 set_local(i, value);
twisti@2047 45 }
twisti@2047 46
twisti@2047 47 for (int i = state->stack_depth() - 1; i >= 0; i--) {
twisti@2047 48 SharkValue *value = state->stack(i);
twisti@2047 49 if (value)
twisti@2047 50 value = value->clone();
twisti@2047 51 push(value);
twisti@2047 52 }
twisti@2047 53 }
twisti@2047 54
twisti@2047 55 set_num_monitors(state ? state->num_monitors() : 0);
twisti@2047 56 }
twisti@2047 57
twisti@2047 58 bool SharkState::equal_to(SharkState *other) {
twisti@2047 59 if (target() != other->target())
twisti@2047 60 return false;
twisti@2047 61
twisti@2047 62 if (method() != other->method())
twisti@2047 63 return false;
twisti@2047 64
twisti@2047 65 if (oop_tmp() != other->oop_tmp())
twisti@2047 66 return false;
twisti@2047 67
twisti@2047 68 if (max_locals() != other->max_locals())
twisti@2047 69 return false;
twisti@2047 70
twisti@2047 71 if (stack_depth() != other->stack_depth())
twisti@2047 72 return false;
twisti@2047 73
twisti@2047 74 if (num_monitors() != other->num_monitors())
twisti@2047 75 return false;
twisti@2047 76
twisti@2047 77 if (has_safepointed() != other->has_safepointed())
twisti@2047 78 return false;
twisti@2047 79
twisti@2047 80 // Local variables
twisti@2047 81 for (int i = 0; i < max_locals(); i++) {
twisti@2047 82 SharkValue *value = local(i);
twisti@2047 83 SharkValue *other_value = other->local(i);
twisti@2047 84
twisti@2047 85 if (value == NULL) {
twisti@2047 86 if (other_value != NULL)
twisti@2047 87 return false;
twisti@2047 88 }
twisti@2047 89 else {
twisti@2047 90 if (other_value == NULL)
twisti@2047 91 return false;
twisti@2047 92
twisti@2047 93 if (!value->equal_to(other_value))
twisti@2047 94 return false;
twisti@2047 95 }
twisti@2047 96 }
twisti@2047 97
twisti@2047 98 // Expression stack
twisti@2047 99 for (int i = 0; i < stack_depth(); i++) {
twisti@2047 100 SharkValue *value = stack(i);
twisti@2047 101 SharkValue *other_value = other->stack(i);
twisti@2047 102
twisti@2047 103 if (value == NULL) {
twisti@2047 104 if (other_value != NULL)
twisti@2047 105 return false;
twisti@2047 106 }
twisti@2047 107 else {
twisti@2047 108 if (other_value == NULL)
twisti@2047 109 return false;
twisti@2047 110
twisti@2047 111 if (!value->equal_to(other_value))
twisti@2047 112 return false;
twisti@2047 113 }
twisti@2047 114 }
twisti@2047 115
twisti@2047 116 return true;
twisti@2047 117 }
twisti@2047 118
twisti@2047 119 void SharkState::merge(SharkState* other,
twisti@2047 120 BasicBlock* other_block,
twisti@2047 121 BasicBlock* this_block) {
twisti@2047 122 // Method
twisti@2047 123 Value *this_method = this->method();
twisti@2047 124 Value *other_method = other->method();
twisti@2047 125 if (this_method != other_method) {
twisti@2047 126 PHINode *phi = builder()->CreatePHI(SharkType::methodOop_type(), "method");
twisti@2047 127 phi->addIncoming(this_method, this_block);
twisti@2047 128 phi->addIncoming(other_method, other_block);
twisti@2047 129 set_method(phi);
twisti@2047 130 }
twisti@2047 131
twisti@2047 132 // Temporary oop slot
twisti@2047 133 Value *this_oop_tmp = this->oop_tmp();
twisti@2047 134 Value *other_oop_tmp = other->oop_tmp();
twisti@2047 135 if (this_oop_tmp != other_oop_tmp) {
twisti@2047 136 assert(this_oop_tmp && other_oop_tmp, "can't merge NULL with non-NULL");
twisti@2047 137 PHINode *phi = builder()->CreatePHI(SharkType::oop_type(), "oop_tmp");
twisti@2047 138 phi->addIncoming(this_oop_tmp, this_block);
twisti@2047 139 phi->addIncoming(other_oop_tmp, other_block);
twisti@2047 140 set_oop_tmp(phi);
twisti@2047 141 }
twisti@2047 142
twisti@2047 143 // Monitors
twisti@2047 144 assert(this->num_monitors() == other->num_monitors(), "should be");
twisti@2047 145
twisti@2047 146 // Local variables
twisti@2047 147 assert(this->max_locals() == other->max_locals(), "should be");
twisti@2047 148 for (int i = 0; i < max_locals(); i++) {
twisti@2047 149 SharkValue *this_value = this->local(i);
twisti@2047 150 SharkValue *other_value = other->local(i);
twisti@2047 151 assert((this_value == NULL) == (other_value == NULL), "should be");
twisti@2047 152 if (this_value != NULL) {
twisti@2047 153 char name[18];
twisti@2047 154 snprintf(name, sizeof(name), "local_%d_", i);
twisti@2047 155 set_local(i, this_value->merge(
twisti@2047 156 builder(), other_value, other_block, this_block, name));
twisti@2047 157 }
twisti@2047 158 }
twisti@2047 159
twisti@2047 160 // Expression stack
twisti@2047 161 assert(this->stack_depth() == other->stack_depth(), "should be");
twisti@2047 162 for (int i = 0; i < stack_depth(); i++) {
twisti@2047 163 SharkValue *this_value = this->stack(i);
twisti@2047 164 SharkValue *other_value = other->stack(i);
twisti@2047 165 assert((this_value == NULL) == (other_value == NULL), "should be");
twisti@2047 166 if (this_value != NULL) {
twisti@2047 167 char name[18];
twisti@2047 168 snprintf(name, sizeof(name), "stack_%d_", i);
twisti@2047 169 set_stack(i, this_value->merge(
twisti@2047 170 builder(), other_value, other_block, this_block, name));
twisti@2047 171 }
twisti@2047 172 }
twisti@2047 173
twisti@2047 174 // Safepointed status
twisti@2047 175 set_has_safepointed(this->has_safepointed() && other->has_safepointed());
twisti@2047 176 }
twisti@2047 177
twisti@2047 178 void SharkState::replace_all(SharkValue* old_value, SharkValue* new_value) {
twisti@2047 179 // Local variables
twisti@2047 180 for (int i = 0; i < max_locals(); i++) {
twisti@2047 181 if (local(i) == old_value)
twisti@2047 182 set_local(i, new_value);
twisti@2047 183 }
twisti@2047 184
twisti@2047 185 // Expression stack
twisti@2047 186 for (int i = 0; i < stack_depth(); i++) {
twisti@2047 187 if (stack(i) == old_value)
twisti@2047 188 set_stack(i, new_value);
twisti@2047 189 }
twisti@2047 190 }
twisti@2047 191
twisti@2047 192 SharkNormalEntryState::SharkNormalEntryState(SharkTopLevelBlock* block,
twisti@2047 193 Value* method)
twisti@2047 194 : SharkState(block) {
twisti@2047 195 assert(!block->stack_depth_at_entry(), "entry block shouldn't have stack");
twisti@2047 196
twisti@2047 197 // Local variables
twisti@2047 198 for (int i = 0; i < max_locals(); i++) {
twisti@2047 199 ciType *type = block->local_type_at_entry(i);
twisti@2047 200
twisti@2047 201 SharkValue *value = NULL;
twisti@2047 202 switch (type->basic_type()) {
twisti@2047 203 case T_INT:
twisti@2047 204 case T_LONG:
twisti@2047 205 case T_FLOAT:
twisti@2047 206 case T_DOUBLE:
twisti@2047 207 case T_OBJECT:
twisti@2047 208 case T_ARRAY:
twisti@2047 209 if (i >= arg_size()) {
twisti@2047 210 ShouldNotReachHere();
twisti@2047 211 }
twisti@2047 212 value = SharkValue::create_generic(type, NULL, i == 0 && !is_static());
twisti@2047 213 break;
twisti@2047 214
twisti@2047 215 case ciTypeFlow::StateVector::T_NULL:
twisti@2047 216 value = SharkValue::null();
twisti@2047 217 break;
twisti@2047 218
twisti@2047 219 case ciTypeFlow::StateVector::T_BOTTOM:
twisti@2047 220 break;
twisti@2047 221
twisti@2047 222 case ciTypeFlow::StateVector::T_LONG2:
twisti@2047 223 case ciTypeFlow::StateVector::T_DOUBLE2:
twisti@2047 224 break;
twisti@2047 225
twisti@2047 226 default:
twisti@2047 227 ShouldNotReachHere();
twisti@2047 228 }
twisti@2047 229 set_local(i, value);
twisti@2047 230 }
twisti@2047 231 SharkNormalEntryCacher(block->function(), method).scan(this);
twisti@2047 232 }
twisti@2047 233
twisti@2047 234 SharkOSREntryState::SharkOSREntryState(SharkTopLevelBlock* block,
twisti@2047 235 Value* method,
twisti@2047 236 Value* osr_buf)
twisti@2047 237 : SharkState(block) {
twisti@2047 238 assert(!block->stack_depth_at_entry(), "entry block shouldn't have stack");
twisti@2047 239 set_num_monitors(block->ciblock()->monitor_count());
twisti@2047 240
twisti@2047 241 // Local variables
twisti@2047 242 for (int i = 0; i < max_locals(); i++) {
twisti@2047 243 ciType *type = block->local_type_at_entry(i);
twisti@2047 244
twisti@2047 245 SharkValue *value = NULL;
twisti@2047 246 switch (type->basic_type()) {
twisti@2047 247 case T_INT:
twisti@2047 248 case T_LONG:
twisti@2047 249 case T_FLOAT:
twisti@2047 250 case T_DOUBLE:
twisti@2047 251 case T_OBJECT:
twisti@2047 252 case T_ARRAY:
twisti@2047 253 value = SharkValue::create_generic(type, NULL, false);
twisti@2047 254 break;
twisti@2047 255
twisti@2047 256 case ciTypeFlow::StateVector::T_NULL:
twisti@2047 257 value = SharkValue::null();
twisti@2047 258 break;
twisti@2047 259
twisti@2047 260 case ciTypeFlow::StateVector::T_BOTTOM:
twisti@2047 261 break;
twisti@2047 262
twisti@2047 263 case ciTypeFlow::StateVector::T_LONG2:
twisti@2047 264 case ciTypeFlow::StateVector::T_DOUBLE2:
twisti@2047 265 break;
twisti@2047 266
twisti@2047 267 default:
twisti@2047 268 ShouldNotReachHere();
twisti@2047 269 }
twisti@2047 270 set_local(i, value);
twisti@2047 271 }
twisti@2047 272 SharkOSREntryCacher(block->function(), method, osr_buf).scan(this);
twisti@2047 273 }
twisti@2047 274
twisti@2047 275 SharkPHIState::SharkPHIState(SharkTopLevelBlock* block)
twisti@2047 276 : SharkState(block), _block(block) {
twisti@2047 277 BasicBlock *saved_insert_point = builder()->GetInsertBlock();
twisti@2047 278 builder()->SetInsertPoint(block->entry_block());
twisti@2047 279 char name[18];
twisti@2047 280
twisti@2047 281 // Method
twisti@2047 282 set_method(builder()->CreatePHI(SharkType::methodOop_type(), "method"));
twisti@2047 283
twisti@2047 284 // Local variables
twisti@2047 285 for (int i = 0; i < max_locals(); i++) {
twisti@2047 286 ciType *type = block->local_type_at_entry(i);
twisti@2047 287 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
twisti@2047 288 // XXX we could do all kinds of clever stuff here
twisti@2047 289 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
twisti@2047 290 }
twisti@2047 291
twisti@2047 292 SharkValue *value = NULL;
twisti@2047 293 switch (type->basic_type()) {
twisti@2047 294 case T_INT:
twisti@2047 295 case T_LONG:
twisti@2047 296 case T_FLOAT:
twisti@2047 297 case T_DOUBLE:
twisti@2047 298 case T_OBJECT:
twisti@2047 299 case T_ARRAY:
twisti@2047 300 snprintf(name, sizeof(name), "local_%d_", i);
twisti@2047 301 value = SharkValue::create_phi(
twisti@2047 302 type, builder()->CreatePHI(SharkType::to_stackType(type), name));
twisti@2047 303 break;
twisti@2047 304
twisti@2047 305 case T_ADDRESS:
twisti@2047 306 value = SharkValue::address_constant(type->as_return_address()->bci());
twisti@2047 307 break;
twisti@2047 308
twisti@2047 309 case ciTypeFlow::StateVector::T_BOTTOM:
twisti@2047 310 break;
twisti@2047 311
twisti@2047 312 case ciTypeFlow::StateVector::T_LONG2:
twisti@2047 313 case ciTypeFlow::StateVector::T_DOUBLE2:
twisti@2047 314 break;
twisti@2047 315
twisti@2047 316 default:
twisti@2047 317 ShouldNotReachHere();
twisti@2047 318 }
twisti@2047 319 set_local(i, value);
twisti@2047 320 }
twisti@2047 321
twisti@2047 322 // Expression stack
twisti@2047 323 for (int i = 0; i < block->stack_depth_at_entry(); i++) {
twisti@2047 324 ciType *type = block->stack_type_at_entry(i);
twisti@2047 325 if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {
twisti@2047 326 // XXX we could do all kinds of clever stuff here
twisti@2047 327 type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?
twisti@2047 328 }
twisti@2047 329
twisti@2047 330 SharkValue *value = NULL;
twisti@2047 331 switch (type->basic_type()) {
twisti@2047 332 case T_INT:
twisti@2047 333 case T_LONG:
twisti@2047 334 case T_FLOAT:
twisti@2047 335 case T_DOUBLE:
twisti@2047 336 case T_OBJECT:
twisti@2047 337 case T_ARRAY:
twisti@2047 338 snprintf(name, sizeof(name), "stack_%d_", i);
twisti@2047 339 value = SharkValue::create_phi(
twisti@2047 340 type, builder()->CreatePHI(SharkType::to_stackType(type), name));
twisti@2047 341 break;
twisti@2047 342
twisti@2047 343 case T_ADDRESS:
twisti@2047 344 value = SharkValue::address_constant(type->as_return_address()->bci());
twisti@2047 345 break;
twisti@2047 346
twisti@2047 347 case ciTypeFlow::StateVector::T_LONG2:
twisti@2047 348 case ciTypeFlow::StateVector::T_DOUBLE2:
twisti@2047 349 break;
twisti@2047 350
twisti@2047 351 default:
twisti@2047 352 ShouldNotReachHere();
twisti@2047 353 }
twisti@2047 354 push(value);
twisti@2047 355 }
twisti@2047 356
twisti@2047 357 // Monitors
twisti@2047 358 set_num_monitors(block->ciblock()->monitor_count());
twisti@2047 359
twisti@2047 360 builder()->SetInsertPoint(saved_insert_point);
twisti@2047 361 }
twisti@2047 362
twisti@2047 363 void SharkPHIState::add_incoming(SharkState* incoming_state) {
twisti@2047 364 BasicBlock *predecessor = builder()->GetInsertBlock();
twisti@2047 365
twisti@2047 366 // Method
twisti@2047 367 ((PHINode *) method())->addIncoming(incoming_state->method(), predecessor);
twisti@2047 368
twisti@2047 369 // Local variables
twisti@2047 370 for (int i = 0; i < max_locals(); i++) {
twisti@2047 371 if (local(i) != NULL)
twisti@2047 372 local(i)->addIncoming(incoming_state->local(i), predecessor);
twisti@2047 373 }
twisti@2047 374
twisti@2047 375 // Expression stack
twisti@2047 376 int stack_depth = block()->stack_depth_at_entry();
twisti@2047 377 assert(stack_depth == incoming_state->stack_depth(), "should be");
twisti@2047 378 for (int i = 0; i < stack_depth; i++) {
twisti@2047 379 assert((stack(i) == NULL) == (incoming_state->stack(i) == NULL), "oops");
twisti@2047 380 if (stack(i))
twisti@2047 381 stack(i)->addIncoming(incoming_state->stack(i), predecessor);
twisti@2047 382 }
twisti@2047 383
twisti@2047 384 // Monitors
twisti@2047 385 assert(num_monitors() == incoming_state->num_monitors(), "should be");
twisti@2047 386
twisti@2047 387 // Temporary oop slot
twisti@2047 388 assert(oop_tmp() == incoming_state->oop_tmp(), "should be");
twisti@2047 389 }

mercurial