src/share/vm/shark/sharkState.cpp

Tue, 18 Jun 2013 12:31:07 -0700

author
johnc
date
Tue, 18 Jun 2013 12:31:07 -0700
changeset 5277
01522ca68fc7
parent 4314
2cd5e15048e6
child 6876
710a3c8b516e
permissions
-rw-r--r--

8015237: Parallelize string table scanning during strong root processing
Summary: Parallelize the scanning of the intern string table by having each GC worker claim a given number of buckets. Changes were also reviewed by Per Liden <per.liden@oracle.com>.
Reviewed-by: tschatzl, stefank, twisti

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

mercurial