Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * Copyright 2008, 2009 Red Hat, Inc. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | #include "precompiled.hpp" |
aoqi@0 | 27 | #include "ci/ciMethod.hpp" |
aoqi@0 | 28 | #include "code/debugInfoRec.hpp" |
aoqi@0 | 29 | #include "shark/llvmValue.hpp" |
aoqi@0 | 30 | #include "shark/sharkBuilder.hpp" |
aoqi@0 | 31 | #include "shark/sharkCacheDecache.hpp" |
aoqi@0 | 32 | #include "shark/sharkFunction.hpp" |
aoqi@0 | 33 | #include "shark/sharkState.hpp" |
aoqi@0 | 34 | |
aoqi@0 | 35 | using namespace llvm; |
aoqi@0 | 36 | |
aoqi@0 | 37 | void SharkDecacher::start_frame() { |
aoqi@0 | 38 | // Start recording the debug information |
aoqi@0 | 39 | _pc_offset = code_buffer()->create_unique_offset(); |
aoqi@0 | 40 | _oopmap = new OopMap( |
aoqi@0 | 41 | oopmap_slot_munge(stack()->oopmap_frame_size()), |
aoqi@0 | 42 | oopmap_slot_munge(arg_size())); |
aoqi@0 | 43 | debug_info()->add_safepoint(pc_offset(), oopmap()); |
aoqi@0 | 44 | } |
aoqi@0 | 45 | |
aoqi@0 | 46 | void SharkDecacher::start_stack(int stack_depth) { |
aoqi@0 | 47 | // Create the array we'll record our stack slots in |
aoqi@0 | 48 | _exparray = new GrowableArray<ScopeValue*>(stack_depth); |
aoqi@0 | 49 | |
aoqi@0 | 50 | // Set the stack pointer |
aoqi@0 | 51 | stack()->CreateStoreStackPointer( |
aoqi@0 | 52 | builder()->CreatePtrToInt( |
aoqi@0 | 53 | stack()->slot_addr( |
aoqi@0 | 54 | stack()->stack_slots_offset() + max_stack() - stack_depth), |
aoqi@0 | 55 | SharkType::intptr_type())); |
aoqi@0 | 56 | } |
aoqi@0 | 57 | |
aoqi@0 | 58 | void SharkDecacher::process_stack_slot(int index, |
aoqi@0 | 59 | SharkValue** addr, |
aoqi@0 | 60 | int offset) { |
aoqi@0 | 61 | SharkValue *value = *addr; |
aoqi@0 | 62 | |
aoqi@0 | 63 | // Write the value to the frame if necessary |
aoqi@0 | 64 | if (stack_slot_needs_write(index, value)) { |
aoqi@0 | 65 | write_value_to_frame( |
aoqi@0 | 66 | SharkType::to_stackType(value->basic_type()), |
aoqi@0 | 67 | value->generic_value(), |
aoqi@0 | 68 | adjusted_offset(value, offset)); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | |
aoqi@0 | 71 | // Record the value in the oopmap if necessary |
aoqi@0 | 72 | if (stack_slot_needs_oopmap(index, value)) { |
aoqi@0 | 73 | oopmap()->set_oop(slot2reg(offset)); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | // Record the value in the debuginfo if necessary |
aoqi@0 | 77 | if (stack_slot_needs_debuginfo(index, value)) { |
aoqi@0 | 78 | exparray()->append(slot2lv(offset, stack_location_type(index, addr))); |
aoqi@0 | 79 | } |
aoqi@0 | 80 | } |
aoqi@0 | 81 | |
aoqi@0 | 82 | void SharkDecacher::start_monitors(int num_monitors) { |
aoqi@0 | 83 | // Create the array we'll record our monitors in |
aoqi@0 | 84 | _monarray = new GrowableArray<MonitorValue*>(num_monitors); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | void SharkDecacher::process_monitor(int index, int box_offset, int obj_offset) { |
aoqi@0 | 88 | oopmap()->set_oop(slot2reg(obj_offset)); |
aoqi@0 | 89 | |
aoqi@0 | 90 | monarray()->append(new MonitorValue( |
aoqi@0 | 91 | slot2lv (obj_offset, Location::oop), |
aoqi@0 | 92 | slot2loc(box_offset, Location::normal))); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | void SharkDecacher::process_oop_tmp_slot(Value** value, int offset) { |
aoqi@0 | 96 | // Decache the temporary oop slot |
aoqi@0 | 97 | if (*value) { |
aoqi@0 | 98 | write_value_to_frame( |
aoqi@0 | 99 | SharkType::oop_type(), |
aoqi@0 | 100 | *value, |
aoqi@0 | 101 | offset); |
aoqi@0 | 102 | |
aoqi@0 | 103 | oopmap()->set_oop(slot2reg(offset)); |
aoqi@0 | 104 | } |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | void SharkDecacher::process_method_slot(Value** value, int offset) { |
aoqi@0 | 108 | // Decache the method pointer |
aoqi@0 | 109 | write_value_to_frame( |
aoqi@0 | 110 | SharkType::Method_type(), |
aoqi@0 | 111 | *value, |
aoqi@0 | 112 | offset); |
aoqi@0 | 113 | |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | void SharkDecacher::process_pc_slot(int offset) { |
aoqi@0 | 117 | // Record the PC |
aoqi@0 | 118 | builder()->CreateStore( |
aoqi@0 | 119 | builder()->code_buffer_address(pc_offset()), |
aoqi@0 | 120 | stack()->slot_addr(offset)); |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | void SharkDecacher::start_locals() { |
aoqi@0 | 124 | // Create the array we'll record our local variables in |
aoqi@0 | 125 | _locarray = new GrowableArray<ScopeValue*>(max_locals());} |
aoqi@0 | 126 | |
aoqi@0 | 127 | void SharkDecacher::process_local_slot(int index, |
aoqi@0 | 128 | SharkValue** addr, |
aoqi@0 | 129 | int offset) { |
aoqi@0 | 130 | SharkValue *value = *addr; |
aoqi@0 | 131 | |
aoqi@0 | 132 | // Write the value to the frame if necessary |
aoqi@0 | 133 | if (local_slot_needs_write(index, value)) { |
aoqi@0 | 134 | write_value_to_frame( |
aoqi@0 | 135 | SharkType::to_stackType(value->basic_type()), |
aoqi@0 | 136 | value->generic_value(), |
aoqi@0 | 137 | adjusted_offset(value, offset)); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | // Record the value in the oopmap if necessary |
aoqi@0 | 141 | if (local_slot_needs_oopmap(index, value)) { |
aoqi@0 | 142 | oopmap()->set_oop(slot2reg(offset)); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | // Record the value in the debuginfo if necessary |
aoqi@0 | 146 | if (local_slot_needs_debuginfo(index, value)) { |
aoqi@0 | 147 | locarray()->append(slot2lv(offset, local_location_type(index, addr))); |
aoqi@0 | 148 | } |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | void SharkDecacher::end_frame() { |
aoqi@0 | 152 | // Record the scope |
aoqi@0 | 153 | debug_info()->describe_scope( |
aoqi@0 | 154 | pc_offset(), |
aoqi@0 | 155 | target(), |
aoqi@0 | 156 | bci(), |
aoqi@0 | 157 | true, |
aoqi@0 | 158 | false, |
aoqi@0 | 159 | false, |
aoqi@0 | 160 | debug_info()->create_scope_values(locarray()), |
aoqi@0 | 161 | debug_info()->create_scope_values(exparray()), |
aoqi@0 | 162 | debug_info()->create_monitor_values(monarray())); |
aoqi@0 | 163 | |
aoqi@0 | 164 | // Finish recording the debug information |
aoqi@0 | 165 | debug_info()->end_safepoint(pc_offset()); |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | void SharkCacher::process_stack_slot(int index, |
aoqi@0 | 169 | SharkValue** addr, |
aoqi@0 | 170 | int offset) { |
aoqi@0 | 171 | SharkValue *value = *addr; |
aoqi@0 | 172 | |
aoqi@0 | 173 | // Read the value from the frame if necessary |
aoqi@0 | 174 | if (stack_slot_needs_read(index, value)) { |
aoqi@0 | 175 | *addr = SharkValue::create_generic( |
aoqi@0 | 176 | value->type(), |
aoqi@0 | 177 | read_value_from_frame( |
aoqi@0 | 178 | SharkType::to_stackType(value->basic_type()), |
aoqi@0 | 179 | adjusted_offset(value, offset)), |
aoqi@0 | 180 | value->zero_checked()); |
aoqi@0 | 181 | } |
aoqi@0 | 182 | } |
aoqi@0 | 183 | |
aoqi@0 | 184 | void SharkOSREntryCacher::process_monitor(int index, |
aoqi@0 | 185 | int box_offset, |
aoqi@0 | 186 | int obj_offset) { |
aoqi@0 | 187 | // Copy the monitor from the OSR buffer to the frame |
aoqi@0 | 188 | int src_offset = max_locals() + index * 2; |
aoqi@0 | 189 | builder()->CreateStore( |
aoqi@0 | 190 | builder()->CreateLoad( |
aoqi@0 | 191 | CreateAddressOfOSRBufEntry(src_offset, SharkType::intptr_type())), |
aoqi@0 | 192 | stack()->slot_addr(box_offset, SharkType::intptr_type())); |
aoqi@0 | 193 | builder()->CreateStore( |
aoqi@0 | 194 | builder()->CreateLoad( |
aoqi@0 | 195 | CreateAddressOfOSRBufEntry(src_offset + 1, SharkType::oop_type())), |
aoqi@0 | 196 | stack()->slot_addr(obj_offset, SharkType::oop_type())); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | void SharkCacher::process_oop_tmp_slot(Value** value, int offset) { |
aoqi@0 | 200 | // Cache the temporary oop |
aoqi@0 | 201 | if (*value) |
aoqi@0 | 202 | *value = read_value_from_frame(SharkType::oop_type(), offset); |
aoqi@0 | 203 | } |
aoqi@0 | 204 | |
aoqi@0 | 205 | void SharkCacher::process_method_slot(Value** value, int offset) { |
aoqi@0 | 206 | // Cache the method pointer |
aoqi@0 | 207 | *value = read_value_from_frame(SharkType::Method_type(), offset); |
aoqi@0 | 208 | } |
aoqi@0 | 209 | |
aoqi@0 | 210 | void SharkFunctionEntryCacher::process_method_slot(Value** value, int offset) { |
aoqi@0 | 211 | // "Cache" the method pointer |
aoqi@0 | 212 | *value = method(); |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | void SharkCacher::process_local_slot(int index, |
aoqi@0 | 216 | SharkValue** addr, |
aoqi@0 | 217 | int offset) { |
aoqi@0 | 218 | SharkValue *value = *addr; |
aoqi@0 | 219 | |
aoqi@0 | 220 | // Read the value from the frame if necessary |
aoqi@0 | 221 | if (local_slot_needs_read(index, value)) { |
aoqi@0 | 222 | *addr = SharkValue::create_generic( |
aoqi@0 | 223 | value->type(), |
aoqi@0 | 224 | read_value_from_frame( |
aoqi@0 | 225 | SharkType::to_stackType(value->basic_type()), |
aoqi@0 | 226 | adjusted_offset(value, offset)), |
aoqi@0 | 227 | value->zero_checked()); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | Value* SharkOSREntryCacher::CreateAddressOfOSRBufEntry(int offset, |
aoqi@0 | 232 | Type* type) { |
aoqi@0 | 233 | Value *result = builder()->CreateStructGEP(osr_buf(), offset); |
aoqi@0 | 234 | if (type != SharkType::intptr_type()) |
aoqi@0 | 235 | result = builder()->CreateBitCast(result, PointerType::getUnqual(type)); |
aoqi@0 | 236 | return result; |
aoqi@0 | 237 | } |
aoqi@0 | 238 | |
aoqi@0 | 239 | void SharkOSREntryCacher::process_local_slot(int index, |
aoqi@0 | 240 | SharkValue** addr, |
aoqi@0 | 241 | int offset) { |
aoqi@0 | 242 | SharkValue *value = *addr; |
aoqi@0 | 243 | |
aoqi@0 | 244 | // Read the value from the OSR buffer if necessary |
aoqi@0 | 245 | if (local_slot_needs_read(index, value)) { |
aoqi@0 | 246 | *addr = SharkValue::create_generic( |
aoqi@0 | 247 | value->type(), |
aoqi@0 | 248 | builder()->CreateLoad( |
aoqi@0 | 249 | CreateAddressOfOSRBufEntry( |
aoqi@0 | 250 | adjusted_offset(value, max_locals() - 1 - index), |
aoqi@0 | 251 | SharkType::to_stackType(value->basic_type()))), |
aoqi@0 | 252 | value->zero_checked()); |
aoqi@0 | 253 | } |
aoqi@0 | 254 | } |
aoqi@0 | 255 | |
aoqi@0 | 256 | void SharkDecacher::write_value_to_frame(Type* type, |
aoqi@0 | 257 | Value* value, |
aoqi@0 | 258 | int offset) { |
aoqi@0 | 259 | builder()->CreateStore(value, stack()->slot_addr(offset, type)); |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | Value* SharkCacher::read_value_from_frame(Type* type, int offset) { |
aoqi@0 | 263 | return builder()->CreateLoad(stack()->slot_addr(offset, type)); |
aoqi@0 | 264 | } |