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

mercurial