src/share/vm/shark/sharkStack.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, 2010 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 "shark/llvmHeaders.hpp"
stefank@2314 28 #include "shark/sharkFunction.hpp"
stefank@2314 29 #include "shark/sharkNativeWrapper.hpp"
stefank@2314 30 #include "shark/sharkStack.hpp"
stefank@2314 31 #include "shark/sharkType.hpp"
twisti@2047 32
twisti@2047 33 using namespace llvm;
twisti@2047 34
twisti@2047 35 void SharkStack::initialize(Value* method) {
twisti@2047 36 bool setup_sp_and_method = (method != NULL);
twisti@2047 37
twisti@2047 38 int locals_words = max_locals();
twisti@2047 39 int extra_locals = locals_words - arg_size();
twisti@2047 40 int header_words = SharkFrame::header_words;
twisti@2047 41 int monitor_words = max_monitors()*frame::interpreter_frame_monitor_size();
twisti@2047 42 int stack_words = max_stack();
twisti@2047 43 int frame_words = header_words + monitor_words + stack_words;
twisti@2047 44
twisti@2047 45 _extended_frame_size = frame_words + locals_words;
twisti@2047 46
twisti@2047 47 // Update the stack pointer
twisti@2047 48 Value *stack_pointer = builder()->CreateSub(
twisti@2047 49 CreateLoadStackPointer(),
twisti@2047 50 LLVMValue::intptr_constant((frame_words + extra_locals) * wordSize));
twisti@2047 51 CreateStackOverflowCheck(stack_pointer);
twisti@2047 52 if (setup_sp_and_method)
twisti@2047 53 CreateStoreStackPointer(stack_pointer);
twisti@2047 54
twisti@2047 55 // Create the frame
twisti@2047 56 _frame = builder()->CreateIntToPtr(
twisti@2047 57 stack_pointer,
twisti@2047 58 PointerType::getUnqual(
twisti@2047 59 ArrayType::get(SharkType::intptr_type(), extended_frame_size())),
twisti@2047 60 "frame");
twisti@2047 61 int offset = 0;
twisti@2047 62
twisti@2047 63 // Expression stack
twisti@2047 64 _stack_slots_offset = offset;
twisti@2047 65 offset += stack_words;
twisti@2047 66
twisti@2047 67 // Monitors
twisti@2047 68 _monitors_slots_offset = offset;
twisti@2047 69 offset += monitor_words;
twisti@2047 70
twisti@2047 71 // Temporary oop slot
twisti@2047 72 _oop_tmp_slot_offset = offset++;
twisti@2047 73
twisti@2047 74 // Method pointer
twisti@2047 75 _method_slot_offset = offset++;
twisti@2047 76 if (setup_sp_and_method) {
twisti@2047 77 builder()->CreateStore(
twisti@4314 78 method, slot_addr(method_slot_offset(), SharkType::Method_type()));
twisti@2047 79 }
twisti@2047 80
twisti@2047 81 // Unextended SP
twisti@2047 82 builder()->CreateStore(stack_pointer, slot_addr(offset++));
twisti@2047 83
twisti@2047 84 // PC
twisti@2047 85 _pc_slot_offset = offset++;
twisti@2047 86
twisti@2047 87 // Frame header
twisti@2047 88 builder()->CreateStore(
twisti@2047 89 LLVMValue::intptr_constant(ZeroFrame::SHARK_FRAME), slot_addr(offset++));
twisti@2047 90 Value *fp = slot_addr(offset++);
twisti@2047 91
twisti@2047 92 // Local variables
twisti@2047 93 _locals_slots_offset = offset;
twisti@2047 94 offset += locals_words;
twisti@2047 95
twisti@2047 96 // Push the frame
twisti@2047 97 assert(offset == extended_frame_size(), "should do");
twisti@2047 98 builder()->CreateStore(CreateLoadFramePointer(), fp);
twisti@2047 99 CreateStoreFramePointer(
twisti@2047 100 builder()->CreatePtrToInt(fp, SharkType::intptr_type()));
twisti@2047 101 }
twisti@2047 102
twisti@2047 103 // This function should match ZeroStack::overflow_check
twisti@2047 104 void SharkStack::CreateStackOverflowCheck(Value* sp) {
twisti@2047 105 BasicBlock *zero_ok = CreateBlock("zero_stack_ok");
twisti@2047 106 BasicBlock *overflow = CreateBlock("stack_overflow");
twisti@2047 107 BasicBlock *abi_ok = CreateBlock("abi_stack_ok");
twisti@2047 108
twisti@2047 109 // Check the Zero stack
twisti@2047 110 builder()->CreateCondBr(
twisti@2047 111 builder()->CreateICmpULT(sp, stack_base()),
twisti@2047 112 overflow, zero_ok);
twisti@2047 113
twisti@2047 114 // Check the ABI stack
twisti@2047 115 builder()->SetInsertPoint(zero_ok);
twisti@2047 116 Value *stack_top = builder()->CreateSub(
twisti@2047 117 builder()->CreateValueOfStructEntry(
twisti@2047 118 thread(),
twisti@2047 119 Thread::stack_base_offset(),
twisti@2047 120 SharkType::intptr_type(),
twisti@2047 121 "abi_base"),
twisti@2047 122 builder()->CreateValueOfStructEntry(
twisti@2047 123 thread(),
twisti@2047 124 Thread::stack_size_offset(),
twisti@2047 125 SharkType::intptr_type(),
twisti@2047 126 "abi_size"));
twisti@2047 127 Value *free_stack = builder()->CreateSub(
twisti@2047 128 builder()->CreatePtrToInt(
twisti@2047 129 builder()->CreateGetFrameAddress(),
twisti@2047 130 SharkType::intptr_type(),
twisti@2047 131 "abi_sp"),
twisti@2047 132 stack_top);
twisti@2047 133 builder()->CreateCondBr(
twisti@2047 134 builder()->CreateICmpULT(
twisti@2047 135 free_stack,
twisti@2047 136 LLVMValue::intptr_constant(StackShadowPages * os::vm_page_size())),
twisti@2047 137 overflow, abi_ok);
twisti@2047 138
twisti@2047 139 // Handle overflows
twisti@2047 140 builder()->SetInsertPoint(overflow);
twisti@2047 141 builder()->CreateCall(builder()->throw_StackOverflowError(), thread());
twisti@2047 142 builder()->CreateRet(LLVMValue::jint_constant(0));
twisti@2047 143
twisti@2047 144 builder()->SetInsertPoint(abi_ok);
twisti@2047 145 }
twisti@2047 146
twisti@2047 147 Value* SharkStack::CreatePopFrame(int result_slots) {
twisti@2047 148 assert(result_slots >= 0 && result_slots <= 2, "should be");
twisti@2047 149 int locals_to_pop = max_locals() - result_slots;
twisti@2047 150
twisti@2047 151 Value *fp = CreateLoadFramePointer();
twisti@2047 152 Value *sp = builder()->CreateAdd(
twisti@2047 153 fp,
twisti@2047 154 LLVMValue::intptr_constant((1 + locals_to_pop) * wordSize));
twisti@2047 155
twisti@2047 156 CreateStoreStackPointer(sp);
twisti@2047 157 CreateStoreFramePointer(
twisti@2047 158 builder()->CreateLoad(
twisti@2047 159 builder()->CreateIntToPtr(
twisti@2047 160 fp, PointerType::getUnqual(SharkType::intptr_type()))));
twisti@2047 161
twisti@2047 162 return sp;
twisti@2047 163 }
twisti@2047 164
twisti@2047 165 Value* SharkStack::slot_addr(int offset,
twisti@4314 166 Type* type,
twisti@2047 167 const char* name) const {
twisti@2047 168 bool needs_cast = type && type != SharkType::intptr_type();
twisti@2047 169
twisti@2047 170 Value* result = builder()->CreateStructGEP(
twisti@2047 171 _frame, offset, needs_cast ? "" : name);
twisti@2047 172
twisti@2047 173 if (needs_cast) {
twisti@2047 174 result = builder()->CreateBitCast(
twisti@2047 175 result, PointerType::getUnqual(type), name);
twisti@2047 176 }
twisti@2047 177 return result;
twisti@2047 178 }
twisti@2047 179
twisti@2047 180 // The bits that differentiate stacks with normal and native frames on top
twisti@2047 181
twisti@2047 182 SharkStack* SharkStack::CreateBuildAndPushFrame(SharkFunction* function,
twisti@2047 183 Value* method) {
twisti@2047 184 return new SharkStackWithNormalFrame(function, method);
twisti@2047 185 }
twisti@2047 186 SharkStack* SharkStack::CreateBuildAndPushFrame(SharkNativeWrapper* wrapper,
twisti@2047 187 Value* method) {
twisti@2047 188 return new SharkStackWithNativeFrame(wrapper, method);
twisti@2047 189 }
twisti@2047 190
twisti@2047 191 SharkStackWithNormalFrame::SharkStackWithNormalFrame(SharkFunction* function,
twisti@2047 192 Value* method)
twisti@2047 193 : SharkStack(function), _function(function) {
twisti@2047 194 // For normal frames, the stack pointer and the method slot will
twisti@2047 195 // be set during each decache, so it is not necessary to do them
twisti@2047 196 // at the time the frame is created. However, we set them for
twisti@2047 197 // non-PRODUCT builds to make crash dumps easier to understand.
twisti@2047 198 initialize(PRODUCT_ONLY(NULL) NOT_PRODUCT(method));
twisti@2047 199 }
twisti@2047 200 SharkStackWithNativeFrame::SharkStackWithNativeFrame(SharkNativeWrapper* wrp,
twisti@2047 201 Value* method)
twisti@2047 202 : SharkStack(wrp), _wrapper(wrp) {
twisti@2047 203 initialize(method);
twisti@2047 204 }
twisti@2047 205
twisti@2047 206 int SharkStackWithNormalFrame::arg_size() const {
twisti@2047 207 return function()->arg_size();
twisti@2047 208 }
twisti@2047 209 int SharkStackWithNativeFrame::arg_size() const {
twisti@2047 210 return wrapper()->arg_size();
twisti@2047 211 }
twisti@2047 212
twisti@2047 213 int SharkStackWithNormalFrame::max_locals() const {
twisti@2047 214 return function()->max_locals();
twisti@2047 215 }
twisti@2047 216 int SharkStackWithNativeFrame::max_locals() const {
twisti@2047 217 return wrapper()->arg_size();
twisti@2047 218 }
twisti@2047 219
twisti@2047 220 int SharkStackWithNormalFrame::max_stack() const {
twisti@2047 221 return function()->max_stack();
twisti@2047 222 }
twisti@2047 223 int SharkStackWithNativeFrame::max_stack() const {
twisti@2047 224 return 0;
twisti@2047 225 }
twisti@2047 226
twisti@2047 227 int SharkStackWithNormalFrame::max_monitors() const {
twisti@2047 228 return function()->max_monitors();
twisti@2047 229 }
twisti@2047 230 int SharkStackWithNativeFrame::max_monitors() const {
twisti@2047 231 return wrapper()->is_synchronized() ? 1 : 0;
twisti@2047 232 }
twisti@2047 233
twisti@2047 234 BasicBlock* SharkStackWithNormalFrame::CreateBlock(const char* name) const {
twisti@2047 235 return function()->CreateBlock(name);
twisti@2047 236 }
twisti@2047 237 BasicBlock* SharkStackWithNativeFrame::CreateBlock(const char* name) const {
twisti@2047 238 return wrapper()->CreateBlock(name);
twisti@2047 239 }
twisti@2047 240
twisti@2047 241 address SharkStackWithNormalFrame::interpreter_entry_point() const {
twisti@2047 242 return (address) CppInterpreter::normal_entry;
twisti@2047 243 }
twisti@2047 244 address SharkStackWithNativeFrame::interpreter_entry_point() const {
twisti@2047 245 return (address) CppInterpreter::native_entry;
twisti@2047 246 }
twisti@2047 247
twisti@2047 248 #ifndef PRODUCT
twisti@2047 249 void SharkStack::CreateAssertLastJavaSPIsNull() const {
twisti@2047 250 #ifdef ASSERT
twisti@2047 251 BasicBlock *fail = CreateBlock("assert_failed");
twisti@2047 252 BasicBlock *pass = CreateBlock("assert_ok");
twisti@2047 253
twisti@2047 254 builder()->CreateCondBr(
twisti@2047 255 builder()->CreateICmpEQ(
twisti@2047 256 builder()->CreateLoad(last_Java_sp_addr()),
twisti@2047 257 LLVMValue::intptr_constant(0)),
twisti@2047 258 pass, fail);
twisti@2047 259
twisti@2047 260 builder()->SetInsertPoint(fail);
twisti@2047 261 builder()->CreateShouldNotReachHere(__FILE__, __LINE__);
twisti@2047 262 builder()->CreateUnreachable();
twisti@2047 263
twisti@2047 264 builder()->SetInsertPoint(pass);
twisti@2047 265 #endif // ASSERT
twisti@2047 266 }
twisti@2047 267 #endif // !PRODUCT

mercurial