src/share/vm/shark/sharkRuntime.cpp

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

author
johnc
date
Tue, 18 Jun 2013 12:31:07 -0700
changeset 5277
01522ca68fc7
parent 4142
d8ce2825b193
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 "runtime/biasedLocking.hpp"
stefank@2314 28 #include "runtime/deoptimization.hpp"
stefank@2314 29 #include "runtime/thread.hpp"
stefank@2314 30 #include "shark/llvmHeaders.hpp"
stefank@2314 31 #include "shark/sharkRuntime.hpp"
stefank@2314 32 #ifdef TARGET_ARCH_zero
stefank@2314 33 # include "stack_zero.inline.hpp"
stefank@2314 34 #endif
twisti@2047 35
twisti@2047 36 using namespace llvm;
twisti@2047 37
twisti@2047 38 JRT_ENTRY(int, SharkRuntime::find_exception_handler(JavaThread* thread,
twisti@2047 39 int* indexes,
twisti@2047 40 int num_indexes))
twisti@2047 41 constantPoolHandle pool(thread, method(thread)->constants());
twisti@2047 42 KlassHandle exc_klass(thread, ((oop) tos_at(thread, 0))->klass());
twisti@2047 43
twisti@2047 44 for (int i = 0; i < num_indexes; i++) {
coleenp@4037 45 Klass* tmp = pool->klass_at(indexes[i], CHECK_0);
twisti@2047 46 KlassHandle chk_klass(thread, tmp);
twisti@2047 47
twisti@2047 48 if (exc_klass() == chk_klass())
twisti@2047 49 return i;
twisti@2047 50
coleenp@4037 51 if (exc_klass()->is_subtype_of(chk_klass()))
twisti@2047 52 return i;
twisti@2047 53 }
twisti@2047 54
twisti@2047 55 return -1;
twisti@2047 56 JRT_END
twisti@2047 57
twisti@2047 58 JRT_ENTRY(void, SharkRuntime::monitorenter(JavaThread* thread,
twisti@2047 59 BasicObjectLock* lock))
twisti@2047 60 if (PrintBiasedLockingStatistics)
twisti@2047 61 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
twisti@2047 62
twisti@2047 63 Handle object(thread, lock->obj());
twisti@2047 64 assert(Universe::heap()->is_in_reserved_or_null(object()), "should be");
twisti@2047 65 if (UseBiasedLocking) {
twisti@2047 66 // Retry fast entry if bias is revoked to avoid unnecessary inflation
twisti@2047 67 ObjectSynchronizer::fast_enter(object, lock->lock(), true, CHECK);
twisti@2047 68 } else {
twisti@2047 69 ObjectSynchronizer::slow_enter(object, lock->lock(), CHECK);
twisti@2047 70 }
twisti@2047 71 assert(Universe::heap()->is_in_reserved_or_null(lock->obj()), "should be");
twisti@2047 72 JRT_END
twisti@2047 73
twisti@2047 74 JRT_ENTRY(void, SharkRuntime::monitorexit(JavaThread* thread,
twisti@2047 75 BasicObjectLock* lock))
twisti@2047 76 Handle object(thread, lock->obj());
twisti@2047 77 assert(Universe::heap()->is_in_reserved_or_null(object()), "should be");
twisti@2047 78 if (lock == NULL || object()->is_unlocked()) {
twisti@2047 79 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
twisti@2047 80 }
twisti@2047 81 ObjectSynchronizer::slow_exit(object(), lock->lock(), thread);
twisti@2047 82 JRT_END
twisti@2047 83
twisti@2047 84 JRT_ENTRY(void, SharkRuntime::new_instance(JavaThread* thread, int index))
coleenp@4037 85 Klass* k_oop = method(thread)->constants()->klass_at(index, CHECK);
twisti@2047 86 instanceKlassHandle klass(THREAD, k_oop);
twisti@2047 87
twisti@2047 88 // Make sure we are not instantiating an abstract klass
twisti@2047 89 klass->check_valid_for_instantiation(true, CHECK);
twisti@2047 90
twisti@2047 91 // Make sure klass is initialized
twisti@2047 92 klass->initialize(CHECK);
twisti@2047 93
twisti@2047 94 // At this point the class may not be fully initialized
twisti@2047 95 // because of recursive initialization. If it is fully
twisti@2047 96 // initialized & has_finalized is not set, we rewrite
twisti@2047 97 // it into its fast version (Note: no locking is needed
twisti@2047 98 // here since this is an atomic byte write and can be
twisti@2047 99 // done more than once).
twisti@2047 100 //
twisti@2047 101 // Note: In case of classes with has_finalized we don't
twisti@2047 102 // rewrite since that saves us an extra check in
twisti@2047 103 // the fast version which then would call the
twisti@2047 104 // slow version anyway (and do a call back into
twisti@2047 105 // Java).
twisti@2047 106 // If we have a breakpoint, then we don't rewrite
twisti@2047 107 // because the _breakpoint bytecode would be lost.
twisti@2047 108 oop obj = klass->allocate_instance(CHECK);
twisti@2047 109 thread->set_vm_result(obj);
twisti@2047 110 JRT_END
twisti@2047 111
twisti@2047 112 JRT_ENTRY(void, SharkRuntime::newarray(JavaThread* thread,
twisti@2047 113 BasicType type,
twisti@2047 114 int size))
twisti@2047 115 oop obj = oopFactory::new_typeArray(type, size, CHECK);
twisti@2047 116 thread->set_vm_result(obj);
twisti@2047 117 JRT_END
twisti@2047 118
twisti@2047 119 JRT_ENTRY(void, SharkRuntime::anewarray(JavaThread* thread,
twisti@2047 120 int index,
twisti@2047 121 int size))
coleenp@4037 122 Klass* klass = method(thread)->constants()->klass_at(index, CHECK);
twisti@2047 123 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
twisti@2047 124 thread->set_vm_result(obj);
twisti@2047 125 JRT_END
twisti@2047 126
twisti@2047 127 JRT_ENTRY(void, SharkRuntime::multianewarray(JavaThread* thread,
twisti@2047 128 int index,
twisti@2047 129 int ndims,
twisti@2047 130 int* dims))
coleenp@4037 131 Klass* klass = method(thread)->constants()->klass_at(index, CHECK);
coleenp@4142 132 oop obj = ArrayKlass::cast(klass)->multi_allocate(ndims, dims, CHECK);
twisti@2047 133 thread->set_vm_result(obj);
twisti@2047 134 JRT_END
twisti@2047 135
twisti@2047 136 JRT_ENTRY(void, SharkRuntime::register_finalizer(JavaThread* thread,
twisti@2047 137 oop object))
twisti@2047 138 assert(object->is_oop(), "should be");
coleenp@4037 139 assert(object->klass()->has_finalizer(), "should have");
coleenp@4037 140 InstanceKlass::register_finalizer(instanceOop(object), CHECK);
twisti@2047 141 JRT_END
twisti@2047 142
twisti@2047 143 JRT_ENTRY(void, SharkRuntime::throw_ArithmeticException(JavaThread* thread,
twisti@2047 144 const char* file,
twisti@2047 145 int line))
twisti@2047 146 Exceptions::_throw_msg(
twisti@2047 147 thread, file, line,
twisti@2047 148 vmSymbols::java_lang_ArithmeticException(),
twisti@2047 149 "");
twisti@2047 150 JRT_END
twisti@2047 151
twisti@2047 152 JRT_ENTRY(void, SharkRuntime::throw_ArrayIndexOutOfBoundsException(
twisti@2047 153 JavaThread* thread,
twisti@2047 154 const char* file,
twisti@2047 155 int line,
twisti@2047 156 int index))
twisti@2047 157 char msg[jintAsStringSize];
twisti@2047 158 snprintf(msg, sizeof(msg), "%d", index);
twisti@2047 159 Exceptions::_throw_msg(
twisti@2047 160 thread, file, line,
twisti@2047 161 vmSymbols::java_lang_ArrayIndexOutOfBoundsException(),
twisti@2047 162 msg);
twisti@2047 163 JRT_END
twisti@2047 164
twisti@2047 165 JRT_ENTRY(void, SharkRuntime::throw_ClassCastException(JavaThread* thread,
twisti@2047 166 const char* file,
twisti@2047 167 int line))
twisti@2047 168 Exceptions::_throw_msg(
twisti@2047 169 thread, file, line,
twisti@2047 170 vmSymbols::java_lang_ClassCastException(),
twisti@2047 171 "");
twisti@2047 172 JRT_END
twisti@2047 173
twisti@2047 174 JRT_ENTRY(void, SharkRuntime::throw_NullPointerException(JavaThread* thread,
twisti@2047 175 const char* file,
twisti@2047 176 int line))
twisti@2047 177 Exceptions::_throw_msg(
twisti@2047 178 thread, file, line,
twisti@2047 179 vmSymbols::java_lang_NullPointerException(),
twisti@2047 180 "");
twisti@2047 181 JRT_END
twisti@2047 182
twisti@2047 183 // Non-VM calls
twisti@2047 184 // Nothing in these must ever GC!
twisti@2047 185
twisti@2047 186 void SharkRuntime::dump(const char *name, intptr_t value) {
twisti@2047 187 oop valueOop = (oop) value;
twisti@2047 188 tty->print("%s = ", name);
twisti@2047 189 if (valueOop->is_oop(true))
twisti@2047 190 valueOop->print_on(tty);
twisti@2047 191 else if (value >= ' ' && value <= '~')
twisti@2047 192 tty->print("'%c' (%d)", value, value);
twisti@2047 193 else
twisti@2047 194 tty->print("%p", value);
twisti@2047 195 tty->print_cr("");
twisti@2047 196 }
twisti@2047 197
coleenp@4037 198 bool SharkRuntime::is_subtype_of(Klass* check_klass, Klass* object_klass) {
coleenp@4037 199 return object_klass->is_subtype_of(check_klass);
twisti@2047 200 }
twisti@2047 201
twisti@2047 202 int SharkRuntime::uncommon_trap(JavaThread* thread, int trap_request) {
twisti@2047 203 Thread *THREAD = thread;
twisti@2047 204
twisti@2047 205 // In C2, uncommon_trap_blob creates a frame, so all the various
twisti@2047 206 // deoptimization functions expect to find the frame of the method
twisti@2047 207 // being deopted one frame down on the stack. We create a dummy
twisti@2047 208 // frame to mirror this.
twisti@2047 209 FakeStubFrame *stubframe = FakeStubFrame::build(CHECK_0);
twisti@2047 210 thread->push_zero_frame(stubframe);
twisti@2047 211
twisti@2047 212 // Initiate the trap
twisti@2047 213 thread->set_last_Java_frame();
twisti@2047 214 Deoptimization::UnrollBlock *urb =
twisti@2047 215 Deoptimization::uncommon_trap(thread, trap_request);
twisti@2047 216 thread->reset_last_Java_frame();
twisti@2047 217
twisti@2047 218 // Pop our dummy frame and the frame being deoptimized
twisti@2047 219 thread->pop_zero_frame();
twisti@2047 220 thread->pop_zero_frame();
twisti@2047 221
twisti@2047 222 // Push skeleton frames
twisti@2047 223 int number_of_frames = urb->number_of_frames();
twisti@2047 224 for (int i = 0; i < number_of_frames; i++) {
twisti@2047 225 intptr_t size = urb->frame_sizes()[i];
twisti@2047 226 InterpreterFrame *frame = InterpreterFrame::build(size, CHECK_0);
twisti@2047 227 thread->push_zero_frame(frame);
twisti@2047 228 }
twisti@2047 229
twisti@2047 230 // Push another dummy frame
twisti@2047 231 stubframe = FakeStubFrame::build(CHECK_0);
twisti@2047 232 thread->push_zero_frame(stubframe);
twisti@2047 233
twisti@2047 234 // Fill in the skeleton frames
twisti@2047 235 thread->set_last_Java_frame();
twisti@2047 236 Deoptimization::unpack_frames(thread, Deoptimization::Unpack_uncommon_trap);
twisti@2047 237 thread->reset_last_Java_frame();
twisti@2047 238
twisti@2047 239 // Pop our dummy frame
twisti@2047 240 thread->pop_zero_frame();
twisti@2047 241
twisti@2047 242 // Fall back into the interpreter
twisti@2047 243 return number_of_frames;
twisti@2047 244 }
twisti@2047 245
twisti@2047 246 FakeStubFrame* FakeStubFrame::build(TRAPS) {
twisti@2047 247 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
twisti@2047 248 stack->overflow_check(header_words, CHECK_NULL);
twisti@2047 249
twisti@2047 250 stack->push(0); // next_frame, filled in later
twisti@2047 251 intptr_t *fp = stack->sp();
twisti@2047 252 assert(fp - stack->sp() == next_frame_off, "should be");
twisti@2047 253
twisti@2047 254 stack->push(FAKE_STUB_FRAME);
twisti@2047 255 assert(fp - stack->sp() == frame_type_off, "should be");
twisti@2047 256
twisti@2047 257 return (FakeStubFrame *) fp;
twisti@2047 258 }

mercurial