src/share/vm/shark/sharkRuntime.cpp

Mon, 04 Apr 2011 03:02:00 -0700

author
twisti
date
Mon, 04 Apr 2011 03:02:00 -0700
changeset 2729
e863062e521d
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

7032458: Zero and Shark fixes
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

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

mercurial