src/share/vm/shark/sharkCacheDecache.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 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/_sharkCacheDecache.cpp.incl"
twisti@2047 28
twisti@2047 29 using namespace llvm;
twisti@2047 30
twisti@2047 31 void SharkDecacher::start_frame() {
twisti@2047 32 // Start recording the debug information
twisti@2047 33 _pc_offset = code_buffer()->create_unique_offset();
twisti@2047 34 _oopmap = new OopMap(
twisti@2047 35 oopmap_slot_munge(stack()->oopmap_frame_size()),
twisti@2047 36 oopmap_slot_munge(arg_size()));
twisti@2047 37 debug_info()->add_safepoint(pc_offset(), oopmap());
twisti@2047 38 }
twisti@2047 39
twisti@2047 40 void SharkDecacher::start_stack(int stack_depth) {
twisti@2047 41 // Create the array we'll record our stack slots in
twisti@2047 42 _exparray = new GrowableArray<ScopeValue*>(stack_depth);
twisti@2047 43
twisti@2047 44 // Set the stack pointer
twisti@2047 45 stack()->CreateStoreStackPointer(
twisti@2047 46 builder()->CreatePtrToInt(
twisti@2047 47 stack()->slot_addr(
twisti@2047 48 stack()->stack_slots_offset() + max_stack() - stack_depth),
twisti@2047 49 SharkType::intptr_type()));
twisti@2047 50 }
twisti@2047 51
twisti@2047 52 void SharkDecacher::process_stack_slot(int index,
twisti@2047 53 SharkValue** addr,
twisti@2047 54 int offset) {
twisti@2047 55 SharkValue *value = *addr;
twisti@2047 56
twisti@2047 57 // Write the value to the frame if necessary
twisti@2047 58 if (stack_slot_needs_write(index, value)) {
twisti@2047 59 write_value_to_frame(
twisti@2047 60 SharkType::to_stackType(value->basic_type()),
twisti@2047 61 value->generic_value(),
twisti@2047 62 adjusted_offset(value, offset));
twisti@2047 63 }
twisti@2047 64
twisti@2047 65 // Record the value in the oopmap if necessary
twisti@2047 66 if (stack_slot_needs_oopmap(index, value)) {
twisti@2047 67 oopmap()->set_oop(slot2reg(offset));
twisti@2047 68 }
twisti@2047 69
twisti@2047 70 // Record the value in the debuginfo if necessary
twisti@2047 71 if (stack_slot_needs_debuginfo(index, value)) {
twisti@2047 72 exparray()->append(slot2lv(offset, stack_location_type(index, addr)));
twisti@2047 73 }
twisti@2047 74 }
twisti@2047 75
twisti@2047 76 void SharkDecacher::start_monitors(int num_monitors) {
twisti@2047 77 // Create the array we'll record our monitors in
twisti@2047 78 _monarray = new GrowableArray<MonitorValue*>(num_monitors);
twisti@2047 79 }
twisti@2047 80
twisti@2047 81 void SharkDecacher::process_monitor(int index, int box_offset, int obj_offset) {
twisti@2047 82 oopmap()->set_oop(slot2reg(obj_offset));
twisti@2047 83
twisti@2047 84 monarray()->append(new MonitorValue(
twisti@2047 85 slot2lv (obj_offset, Location::oop),
twisti@2047 86 slot2loc(box_offset, Location::normal)));
twisti@2047 87 }
twisti@2047 88
twisti@2047 89 void SharkDecacher::process_oop_tmp_slot(Value** value, int offset) {
twisti@2047 90 // Decache the temporary oop slot
twisti@2047 91 if (*value) {
twisti@2047 92 write_value_to_frame(
twisti@2047 93 SharkType::oop_type(),
twisti@2047 94 *value,
twisti@2047 95 offset);
twisti@2047 96
twisti@2047 97 oopmap()->set_oop(slot2reg(offset));
twisti@2047 98 }
twisti@2047 99 }
twisti@2047 100
twisti@2047 101 void SharkDecacher::process_method_slot(Value** value, int offset) {
twisti@2047 102 // Decache the method pointer
twisti@2047 103 write_value_to_frame(
twisti@2047 104 SharkType::methodOop_type(),
twisti@2047 105 *value,
twisti@2047 106 offset);
twisti@2047 107
twisti@2047 108 oopmap()->set_oop(slot2reg(offset));
twisti@2047 109 }
twisti@2047 110
twisti@2047 111 void SharkDecacher::process_pc_slot(int offset) {
twisti@2047 112 // Record the PC
twisti@2047 113 builder()->CreateStore(
twisti@2047 114 builder()->code_buffer_address(pc_offset()),
twisti@2047 115 stack()->slot_addr(offset));
twisti@2047 116 }
twisti@2047 117
twisti@2047 118 void SharkDecacher::start_locals() {
twisti@2047 119 // Create the array we'll record our local variables in
twisti@2047 120 _locarray = new GrowableArray<ScopeValue*>(max_locals());}
twisti@2047 121
twisti@2047 122 void SharkDecacher::process_local_slot(int index,
twisti@2047 123 SharkValue** addr,
twisti@2047 124 int offset) {
twisti@2047 125 SharkValue *value = *addr;
twisti@2047 126
twisti@2047 127 // Write the value to the frame if necessary
twisti@2047 128 if (local_slot_needs_write(index, value)) {
twisti@2047 129 write_value_to_frame(
twisti@2047 130 SharkType::to_stackType(value->basic_type()),
twisti@2047 131 value->generic_value(),
twisti@2047 132 adjusted_offset(value, offset));
twisti@2047 133 }
twisti@2047 134
twisti@2047 135 // Record the value in the oopmap if necessary
twisti@2047 136 if (local_slot_needs_oopmap(index, value)) {
twisti@2047 137 oopmap()->set_oop(slot2reg(offset));
twisti@2047 138 }
twisti@2047 139
twisti@2047 140 // Record the value in the debuginfo if necessary
twisti@2047 141 if (local_slot_needs_debuginfo(index, value)) {
twisti@2047 142 locarray()->append(slot2lv(offset, local_location_type(index, addr)));
twisti@2047 143 }
twisti@2047 144 }
twisti@2047 145
twisti@2047 146 void SharkDecacher::end_frame() {
twisti@2047 147 // Record the scope
twisti@2047 148 debug_info()->describe_scope(
twisti@2047 149 pc_offset(),
twisti@2047 150 target(),
twisti@2047 151 bci(),
twisti@2047 152 true,
twisti@2047 153 false,
twisti@2047 154 false,
twisti@2047 155 debug_info()->create_scope_values(locarray()),
twisti@2047 156 debug_info()->create_scope_values(exparray()),
twisti@2047 157 debug_info()->create_monitor_values(monarray()));
twisti@2047 158
twisti@2047 159 // Finish recording the debug information
twisti@2047 160 debug_info()->end_safepoint(pc_offset());
twisti@2047 161 }
twisti@2047 162
twisti@2047 163 void SharkCacher::process_stack_slot(int index,
twisti@2047 164 SharkValue** addr,
twisti@2047 165 int offset) {
twisti@2047 166 SharkValue *value = *addr;
twisti@2047 167
twisti@2047 168 // Read the value from the frame if necessary
twisti@2047 169 if (stack_slot_needs_read(index, value)) {
twisti@2047 170 *addr = SharkValue::create_generic(
twisti@2047 171 value->type(),
twisti@2047 172 read_value_from_frame(
twisti@2047 173 SharkType::to_stackType(value->basic_type()),
twisti@2047 174 adjusted_offset(value, offset)),
twisti@2047 175 value->zero_checked());
twisti@2047 176 }
twisti@2047 177 }
twisti@2047 178
twisti@2047 179 void SharkOSREntryCacher::process_monitor(int index,
twisti@2047 180 int box_offset,
twisti@2047 181 int obj_offset) {
twisti@2047 182 // Copy the monitor from the OSR buffer to the frame
twisti@2047 183 int src_offset = max_locals() + index * 2;
twisti@2047 184 builder()->CreateStore(
twisti@2047 185 builder()->CreateLoad(
twisti@2047 186 CreateAddressOfOSRBufEntry(src_offset, SharkType::intptr_type())),
twisti@2047 187 stack()->slot_addr(box_offset, SharkType::intptr_type()));
twisti@2047 188 builder()->CreateStore(
twisti@2047 189 builder()->CreateLoad(
twisti@2047 190 CreateAddressOfOSRBufEntry(src_offset + 1, SharkType::oop_type())),
twisti@2047 191 stack()->slot_addr(obj_offset, SharkType::oop_type()));
twisti@2047 192 }
twisti@2047 193
twisti@2047 194 void SharkCacher::process_oop_tmp_slot(Value** value, int offset) {
twisti@2047 195 // Cache the temporary oop
twisti@2047 196 if (*value)
twisti@2047 197 *value = read_value_from_frame(SharkType::oop_type(), offset);
twisti@2047 198 }
twisti@2047 199
twisti@2047 200 void SharkCacher::process_method_slot(Value** value, int offset) {
twisti@2047 201 // Cache the method pointer
twisti@2047 202 *value = read_value_from_frame(SharkType::methodOop_type(), offset);
twisti@2047 203 }
twisti@2047 204
twisti@2047 205 void SharkFunctionEntryCacher::process_method_slot(Value** value, int offset) {
twisti@2047 206 // "Cache" the method pointer
twisti@2047 207 *value = method();
twisti@2047 208 }
twisti@2047 209
twisti@2047 210 void SharkCacher::process_local_slot(int index,
twisti@2047 211 SharkValue** addr,
twisti@2047 212 int offset) {
twisti@2047 213 SharkValue *value = *addr;
twisti@2047 214
twisti@2047 215 // Read the value from the frame if necessary
twisti@2047 216 if (local_slot_needs_read(index, value)) {
twisti@2047 217 *addr = SharkValue::create_generic(
twisti@2047 218 value->type(),
twisti@2047 219 read_value_from_frame(
twisti@2047 220 SharkType::to_stackType(value->basic_type()),
twisti@2047 221 adjusted_offset(value, offset)),
twisti@2047 222 value->zero_checked());
twisti@2047 223 }
twisti@2047 224 }
twisti@2047 225
twisti@2047 226 Value* SharkOSREntryCacher::CreateAddressOfOSRBufEntry(int offset,
twisti@2047 227 const Type* type) {
twisti@2047 228 Value *result = builder()->CreateStructGEP(osr_buf(), offset);
twisti@2047 229 if (type != SharkType::intptr_type())
twisti@2047 230 result = builder()->CreateBitCast(result, PointerType::getUnqual(type));
twisti@2047 231 return result;
twisti@2047 232 }
twisti@2047 233
twisti@2047 234 void SharkOSREntryCacher::process_local_slot(int index,
twisti@2047 235 SharkValue** addr,
twisti@2047 236 int offset) {
twisti@2047 237 SharkValue *value = *addr;
twisti@2047 238
twisti@2047 239 // Read the value from the OSR buffer if necessary
twisti@2047 240 if (local_slot_needs_read(index, value)) {
twisti@2047 241 *addr = SharkValue::create_generic(
twisti@2047 242 value->type(),
twisti@2047 243 builder()->CreateLoad(
twisti@2047 244 CreateAddressOfOSRBufEntry(
twisti@2047 245 adjusted_offset(value, max_locals() - 1 - index),
twisti@2047 246 SharkType::to_stackType(value->basic_type()))),
twisti@2047 247 value->zero_checked());
twisti@2047 248 }
twisti@2047 249 }
twisti@2047 250
twisti@2047 251 void SharkDecacher::write_value_to_frame(const Type* type,
twisti@2047 252 Value* value,
twisti@2047 253 int offset) {
twisti@2047 254 builder()->CreateStore(value, stack()->slot_addr(offset, type));
twisti@2047 255 }
twisti@2047 256
twisti@2047 257 Value* SharkCacher::read_value_from_frame(const Type* type, int offset) {
twisti@2047 258 return builder()->CreateLoad(stack()->slot_addr(offset, type));
twisti@2047 259 }

mercurial