Tue, 18 Jun 2013 12:31:07 -0700
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 "ci/ciMethod.hpp" |
stefank@2314 | 28 | #include "memory/resourceArea.hpp" |
coleenp@4037 | 29 | #include "oops/method.hpp" |
stefank@2314 | 30 | #include "runtime/os.hpp" |
stefank@2314 | 31 | #include "runtime/synchronizer.hpp" |
stefank@2314 | 32 | #include "runtime/thread.hpp" |
stefank@2314 | 33 | #include "shark/llvmHeaders.hpp" |
stefank@2314 | 34 | #include "shark/llvmValue.hpp" |
stefank@2314 | 35 | #include "shark/sharkBuilder.hpp" |
stefank@2314 | 36 | #include "shark/sharkContext.hpp" |
stefank@2314 | 37 | #include "shark/sharkRuntime.hpp" |
stefank@2314 | 38 | #include "utilities/debug.hpp" |
twisti@2047 | 39 | |
twisti@2047 | 40 | using namespace llvm; |
twisti@2047 | 41 | |
twisti@2047 | 42 | SharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer) |
twisti@2047 | 43 | : IRBuilder<>(SharkContext::current()), |
twisti@2047 | 44 | _code_buffer(code_buffer) { |
twisti@2047 | 45 | } |
twisti@2047 | 46 | |
twisti@2047 | 47 | // Helpers for accessing structures |
twisti@2047 | 48 | Value* SharkBuilder::CreateAddressOfStructEntry(Value* base, |
twisti@2047 | 49 | ByteSize offset, |
twisti@4314 | 50 | Type* type, |
twisti@2047 | 51 | const char* name) { |
twisti@2047 | 52 | return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name); |
twisti@2047 | 53 | } |
twisti@2047 | 54 | |
twisti@2047 | 55 | LoadInst* SharkBuilder::CreateValueOfStructEntry(Value* base, |
twisti@2047 | 56 | ByteSize offset, |
twisti@4314 | 57 | Type* type, |
twisti@2047 | 58 | const char* name) { |
twisti@2047 | 59 | return CreateLoad( |
twisti@2047 | 60 | CreateAddressOfStructEntry( |
twisti@2047 | 61 | base, offset, PointerType::getUnqual(type)), |
twisti@2047 | 62 | name); |
twisti@2047 | 63 | } |
twisti@2047 | 64 | |
twisti@2047 | 65 | // Helpers for accessing arrays |
twisti@2047 | 66 | |
twisti@2047 | 67 | LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) { |
twisti@2047 | 68 | return CreateValueOfStructEntry( |
twisti@2047 | 69 | arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()), |
twisti@2047 | 70 | SharkType::jint_type(), "length"); |
twisti@2047 | 71 | } |
twisti@2047 | 72 | |
twisti@2047 | 73 | Value* SharkBuilder::CreateArrayAddress(Value* arrayoop, |
twisti@4314 | 74 | Type* element_type, |
twisti@2047 | 75 | int element_bytes, |
twisti@2047 | 76 | ByteSize base_offset, |
twisti@2047 | 77 | Value* index, |
twisti@2047 | 78 | const char* name) { |
twisti@2047 | 79 | Value* offset = CreateIntCast(index, SharkType::intptr_type(), false); |
twisti@2047 | 80 | if (element_bytes != 1) |
twisti@2047 | 81 | offset = CreateShl( |
twisti@2047 | 82 | offset, |
twisti@2047 | 83 | LLVMValue::intptr_constant(exact_log2(element_bytes))); |
twisti@2047 | 84 | offset = CreateAdd( |
twisti@2047 | 85 | LLVMValue::intptr_constant(in_bytes(base_offset)), offset); |
twisti@2047 | 86 | |
twisti@2047 | 87 | return CreateIntToPtr( |
twisti@2047 | 88 | CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset), |
twisti@2047 | 89 | PointerType::getUnqual(element_type), |
twisti@2047 | 90 | name); |
twisti@2047 | 91 | } |
twisti@2047 | 92 | |
twisti@2047 | 93 | Value* SharkBuilder::CreateArrayAddress(Value* arrayoop, |
twisti@2047 | 94 | BasicType basic_type, |
twisti@2047 | 95 | ByteSize base_offset, |
twisti@2047 | 96 | Value* index, |
twisti@2047 | 97 | const char* name) { |
twisti@2047 | 98 | return CreateArrayAddress( |
twisti@2047 | 99 | arrayoop, |
twisti@2047 | 100 | SharkType::to_arrayType(basic_type), |
twisti@2047 | 101 | type2aelembytes(basic_type), |
twisti@2047 | 102 | base_offset, index, name); |
twisti@2047 | 103 | } |
twisti@2047 | 104 | |
twisti@2047 | 105 | Value* SharkBuilder::CreateArrayAddress(Value* arrayoop, |
twisti@2047 | 106 | BasicType basic_type, |
twisti@2047 | 107 | Value* index, |
twisti@2047 | 108 | const char* name) { |
twisti@2047 | 109 | return CreateArrayAddress( |
twisti@2047 | 110 | arrayoop, basic_type, |
twisti@2047 | 111 | in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)), |
twisti@2047 | 112 | index, name); |
twisti@2047 | 113 | } |
twisti@2047 | 114 | |
twisti@2047 | 115 | // Helpers for creating intrinsics and external functions. |
twisti@2047 | 116 | |
twisti@4314 | 117 | Type* SharkBuilder::make_type(char type, bool void_ok) { |
twisti@2047 | 118 | switch (type) { |
twisti@2047 | 119 | // Primitive types |
twisti@2047 | 120 | case 'c': |
twisti@2047 | 121 | return SharkType::jbyte_type(); |
twisti@2047 | 122 | case 'i': |
twisti@2047 | 123 | return SharkType::jint_type(); |
twisti@2047 | 124 | case 'l': |
twisti@2047 | 125 | return SharkType::jlong_type(); |
twisti@2047 | 126 | case 'x': |
twisti@2047 | 127 | return SharkType::intptr_type(); |
twisti@2047 | 128 | case 'f': |
twisti@2047 | 129 | return SharkType::jfloat_type(); |
twisti@2047 | 130 | case 'd': |
twisti@2047 | 131 | return SharkType::jdouble_type(); |
twisti@2047 | 132 | |
twisti@2047 | 133 | // Pointers to primitive types |
twisti@2047 | 134 | case 'C': |
twisti@2047 | 135 | case 'I': |
twisti@2047 | 136 | case 'L': |
twisti@2047 | 137 | case 'X': |
twisti@2047 | 138 | case 'F': |
twisti@2047 | 139 | case 'D': |
twisti@2047 | 140 | return PointerType::getUnqual(make_type(tolower(type), false)); |
twisti@2047 | 141 | |
twisti@2047 | 142 | // VM objects |
twisti@2047 | 143 | case 'T': |
twisti@2047 | 144 | return SharkType::thread_type(); |
twisti@2047 | 145 | case 'M': |
twisti@2047 | 146 | return PointerType::getUnqual(SharkType::monitor_type()); |
twisti@2047 | 147 | case 'O': |
twisti@2047 | 148 | return SharkType::oop_type(); |
twisti@4314 | 149 | case 'K': |
twisti@4314 | 150 | return SharkType::klass_type(); |
twisti@2047 | 151 | |
twisti@2047 | 152 | // Miscellaneous |
twisti@2047 | 153 | case 'v': |
twisti@2047 | 154 | assert(void_ok, "should be"); |
twisti@2047 | 155 | return SharkType::void_type(); |
twisti@2047 | 156 | case '1': |
twisti@2047 | 157 | return SharkType::bit_type(); |
twisti@2047 | 158 | |
twisti@2047 | 159 | default: |
twisti@2047 | 160 | ShouldNotReachHere(); |
twisti@2047 | 161 | } |
twisti@2047 | 162 | } |
twisti@2047 | 163 | |
twisti@4314 | 164 | FunctionType* SharkBuilder::make_ftype(const char* params, |
twisti@2047 | 165 | const char* ret) { |
twisti@4314 | 166 | std::vector<Type*> param_types; |
twisti@2047 | 167 | for (const char* c = params; *c; c++) |
twisti@2047 | 168 | param_types.push_back(make_type(*c, false)); |
twisti@2047 | 169 | |
twisti@2047 | 170 | assert(strlen(ret) == 1, "should be"); |
twisti@4314 | 171 | Type *return_type = make_type(*ret, true); |
twisti@2047 | 172 | |
twisti@2047 | 173 | return FunctionType::get(return_type, param_types, false); |
twisti@2047 | 174 | } |
twisti@2047 | 175 | |
twisti@2047 | 176 | // Create an object representing an intrinsic or external function by |
twisti@2047 | 177 | // referencing the symbol by name. This is the LLVM-style approach, |
twisti@2047 | 178 | // but it cannot be used on functions within libjvm.so its symbols |
twisti@2047 | 179 | // are not exported. Note that you cannot make this work simply by |
twisti@2047 | 180 | // exporting the symbols, as some symbols have the same names as |
twisti@2047 | 181 | // symbols in the standard libraries (eg, atan2, fabs) and would |
twisti@2047 | 182 | // obscure them were they visible. |
twisti@2047 | 183 | Value* SharkBuilder::make_function(const char* name, |
twisti@2047 | 184 | const char* params, |
twisti@2047 | 185 | const char* ret) { |
twisti@2047 | 186 | return SharkContext::current().get_external(name, make_ftype(params, ret)); |
twisti@2047 | 187 | } |
twisti@2047 | 188 | |
twisti@2047 | 189 | // Create an object representing an external function by inlining a |
twisti@2047 | 190 | // function pointer in the code. This is not the LLVM way, but it's |
twisti@2047 | 191 | // the only way to access functions in libjvm.so and functions like |
twisti@2047 | 192 | // __kernel_dmb on ARM which is accessed via an absolute address. |
twisti@2047 | 193 | Value* SharkBuilder::make_function(address func, |
twisti@2047 | 194 | const char* params, |
twisti@2047 | 195 | const char* ret) { |
twisti@2047 | 196 | return CreateIntToPtr( |
twisti@2047 | 197 | LLVMValue::intptr_constant((intptr_t) func), |
twisti@2047 | 198 | PointerType::getUnqual(make_ftype(params, ret))); |
twisti@2047 | 199 | } |
twisti@2047 | 200 | |
twisti@2047 | 201 | // VM calls |
twisti@2047 | 202 | |
twisti@2047 | 203 | Value* SharkBuilder::find_exception_handler() { |
twisti@2047 | 204 | return make_function( |
twisti@2047 | 205 | (address) SharkRuntime::find_exception_handler, "TIi", "i"); |
twisti@2047 | 206 | } |
twisti@2047 | 207 | |
twisti@2047 | 208 | Value* SharkBuilder::monitorenter() { |
twisti@2047 | 209 | return make_function((address) SharkRuntime::monitorenter, "TM", "v"); |
twisti@2047 | 210 | } |
twisti@2047 | 211 | |
twisti@2047 | 212 | Value* SharkBuilder::monitorexit() { |
twisti@2047 | 213 | return make_function((address) SharkRuntime::monitorexit, "TM", "v"); |
twisti@2047 | 214 | } |
twisti@2047 | 215 | |
twisti@2047 | 216 | Value* SharkBuilder::new_instance() { |
twisti@2047 | 217 | return make_function((address) SharkRuntime::new_instance, "Ti", "v"); |
twisti@2047 | 218 | } |
twisti@2047 | 219 | |
twisti@2047 | 220 | Value* SharkBuilder::newarray() { |
twisti@2047 | 221 | return make_function((address) SharkRuntime::newarray, "Tii", "v"); |
twisti@2047 | 222 | } |
twisti@2047 | 223 | |
twisti@2047 | 224 | Value* SharkBuilder::anewarray() { |
twisti@2047 | 225 | return make_function((address) SharkRuntime::anewarray, "Tii", "v"); |
twisti@2047 | 226 | } |
twisti@2047 | 227 | |
twisti@2047 | 228 | Value* SharkBuilder::multianewarray() { |
twisti@2047 | 229 | return make_function((address) SharkRuntime::multianewarray, "TiiI", "v"); |
twisti@2047 | 230 | } |
twisti@2047 | 231 | |
twisti@2047 | 232 | Value* SharkBuilder::register_finalizer() { |
twisti@2047 | 233 | return make_function((address) SharkRuntime::register_finalizer, "TO", "v"); |
twisti@2047 | 234 | } |
twisti@2047 | 235 | |
twisti@2047 | 236 | Value* SharkBuilder::safepoint() { |
twisti@2047 | 237 | return make_function((address) SafepointSynchronize::block, "T", "v"); |
twisti@2047 | 238 | } |
twisti@2047 | 239 | |
twisti@2047 | 240 | Value* SharkBuilder::throw_ArithmeticException() { |
twisti@2047 | 241 | return make_function( |
twisti@2047 | 242 | (address) SharkRuntime::throw_ArithmeticException, "TCi", "v"); |
twisti@2047 | 243 | } |
twisti@2047 | 244 | |
twisti@2047 | 245 | Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException() { |
twisti@2047 | 246 | return make_function( |
twisti@2047 | 247 | (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v"); |
twisti@2047 | 248 | } |
twisti@2047 | 249 | |
twisti@2047 | 250 | Value* SharkBuilder::throw_ClassCastException() { |
twisti@2047 | 251 | return make_function( |
twisti@2047 | 252 | (address) SharkRuntime::throw_ClassCastException, "TCi", "v"); |
twisti@2047 | 253 | } |
twisti@2047 | 254 | |
twisti@2047 | 255 | Value* SharkBuilder::throw_NullPointerException() { |
twisti@2047 | 256 | return make_function( |
twisti@2047 | 257 | (address) SharkRuntime::throw_NullPointerException, "TCi", "v"); |
twisti@2047 | 258 | } |
twisti@2047 | 259 | |
twisti@2047 | 260 | // High-level non-VM calls |
twisti@2047 | 261 | |
twisti@2047 | 262 | Value* SharkBuilder::f2i() { |
twisti@2047 | 263 | return make_function((address) SharedRuntime::f2i, "f", "i"); |
twisti@2047 | 264 | } |
twisti@2047 | 265 | |
twisti@2047 | 266 | Value* SharkBuilder::f2l() { |
twisti@2047 | 267 | return make_function((address) SharedRuntime::f2l, "f", "l"); |
twisti@2047 | 268 | } |
twisti@2047 | 269 | |
twisti@2047 | 270 | Value* SharkBuilder::d2i() { |
twisti@2047 | 271 | return make_function((address) SharedRuntime::d2i, "d", "i"); |
twisti@2047 | 272 | } |
twisti@2047 | 273 | |
twisti@2047 | 274 | Value* SharkBuilder::d2l() { |
twisti@2047 | 275 | return make_function((address) SharedRuntime::d2l, "d", "l"); |
twisti@2047 | 276 | } |
twisti@2047 | 277 | |
twisti@2047 | 278 | Value* SharkBuilder::is_subtype_of() { |
twisti@4314 | 279 | return make_function((address) SharkRuntime::is_subtype_of, "KK", "c"); |
twisti@2047 | 280 | } |
twisti@2047 | 281 | |
twisti@2047 | 282 | Value* SharkBuilder::current_time_millis() { |
twisti@2047 | 283 | return make_function((address) os::javaTimeMillis, "", "l"); |
twisti@2047 | 284 | } |
twisti@2047 | 285 | |
twisti@2047 | 286 | Value* SharkBuilder::sin() { |
twisti@2047 | 287 | return make_function("llvm.sin.f64", "d", "d"); |
twisti@2047 | 288 | } |
twisti@2047 | 289 | |
twisti@2047 | 290 | Value* SharkBuilder::cos() { |
twisti@2047 | 291 | return make_function("llvm.cos.f64", "d", "d"); |
twisti@2047 | 292 | } |
twisti@2047 | 293 | |
twisti@2047 | 294 | Value* SharkBuilder::tan() { |
twisti@2047 | 295 | return make_function((address) ::tan, "d", "d"); |
twisti@2047 | 296 | } |
twisti@2047 | 297 | |
twisti@2047 | 298 | Value* SharkBuilder::atan2() { |
twisti@2047 | 299 | return make_function((address) ::atan2, "dd", "d"); |
twisti@2047 | 300 | } |
twisti@2047 | 301 | |
twisti@2047 | 302 | Value* SharkBuilder::sqrt() { |
twisti@2047 | 303 | return make_function("llvm.sqrt.f64", "d", "d"); |
twisti@2047 | 304 | } |
twisti@2047 | 305 | |
twisti@2047 | 306 | Value* SharkBuilder::log() { |
twisti@2047 | 307 | return make_function("llvm.log.f64", "d", "d"); |
twisti@2047 | 308 | } |
twisti@2047 | 309 | |
twisti@2047 | 310 | Value* SharkBuilder::log10() { |
twisti@2047 | 311 | return make_function("llvm.log10.f64", "d", "d"); |
twisti@2047 | 312 | } |
twisti@2047 | 313 | |
twisti@2047 | 314 | Value* SharkBuilder::pow() { |
twisti@2047 | 315 | return make_function("llvm.pow.f64", "dd", "d"); |
twisti@2047 | 316 | } |
twisti@2047 | 317 | |
twisti@2047 | 318 | Value* SharkBuilder::exp() { |
twisti@2047 | 319 | return make_function("llvm.exp.f64", "d", "d"); |
twisti@2047 | 320 | } |
twisti@2047 | 321 | |
twisti@2047 | 322 | Value* SharkBuilder::fabs() { |
twisti@2047 | 323 | return make_function((address) ::fabs, "d", "d"); |
twisti@2047 | 324 | } |
twisti@2047 | 325 | |
twisti@2047 | 326 | Value* SharkBuilder::unsafe_field_offset_to_byte_offset() { |
twisti@2047 | 327 | extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset); |
twisti@2047 | 328 | return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l"); |
twisti@2047 | 329 | } |
twisti@2047 | 330 | |
twisti@2047 | 331 | Value* SharkBuilder::osr_migration_end() { |
twisti@2047 | 332 | return make_function((address) SharedRuntime::OSR_migration_end, "C", "v"); |
twisti@2047 | 333 | } |
twisti@2047 | 334 | |
twisti@2047 | 335 | // Semi-VM calls |
twisti@2047 | 336 | |
twisti@2047 | 337 | Value* SharkBuilder::throw_StackOverflowError() { |
twisti@2047 | 338 | return make_function((address) ZeroStack::handle_overflow, "T", "v"); |
twisti@2047 | 339 | } |
twisti@2047 | 340 | |
twisti@2047 | 341 | Value* SharkBuilder::uncommon_trap() { |
twisti@2047 | 342 | return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i"); |
twisti@2047 | 343 | } |
twisti@2047 | 344 | |
twisti@2047 | 345 | Value* SharkBuilder::deoptimized_entry_point() { |
twisti@2047 | 346 | return make_function((address) CppInterpreter::main_loop, "iT", "v"); |
twisti@2047 | 347 | } |
twisti@2047 | 348 | |
twisti@2047 | 349 | // Native-Java transition |
twisti@2047 | 350 | |
twisti@2047 | 351 | Value* SharkBuilder::check_special_condition_for_native_trans() { |
twisti@2047 | 352 | return make_function( |
twisti@2047 | 353 | (address) JavaThread::check_special_condition_for_native_trans, |
twisti@2047 | 354 | "T", "v"); |
twisti@2047 | 355 | } |
twisti@2047 | 356 | |
twisti@2047 | 357 | Value* SharkBuilder::frame_address() { |
twisti@2047 | 358 | return make_function("llvm.frameaddress", "i", "C"); |
twisti@2047 | 359 | } |
twisti@2047 | 360 | |
twisti@2047 | 361 | Value* SharkBuilder::memset() { |
twisti@2047 | 362 | // LLVM 2.8 added a fifth isVolatile field for memset |
twisti@2047 | 363 | // introduced with LLVM r100304 |
twisti@4314 | 364 | return make_function("llvm.memset.p0i8.i32", "Cciii", "v"); |
twisti@2047 | 365 | } |
twisti@2047 | 366 | |
twisti@2047 | 367 | Value* SharkBuilder::unimplemented() { |
twisti@2047 | 368 | return make_function((address) report_unimplemented, "Ci", "v"); |
twisti@2047 | 369 | } |
twisti@2047 | 370 | |
twisti@2047 | 371 | Value* SharkBuilder::should_not_reach_here() { |
twisti@2047 | 372 | return make_function((address) report_should_not_reach_here, "Ci", "v"); |
twisti@2047 | 373 | } |
twisti@2047 | 374 | |
twisti@2047 | 375 | Value* SharkBuilder::dump() { |
twisti@2047 | 376 | return make_function((address) SharkRuntime::dump, "Cx", "v"); |
twisti@2047 | 377 | } |
twisti@2047 | 378 | |
twisti@2047 | 379 | // Public interface to low-level non-VM calls |
twisti@2047 | 380 | |
twisti@2047 | 381 | CallInst* SharkBuilder::CreateGetFrameAddress() { |
twisti@2047 | 382 | return CreateCall(frame_address(), LLVMValue::jint_constant(0)); |
twisti@2047 | 383 | } |
twisti@2047 | 384 | |
twisti@2047 | 385 | CallInst* SharkBuilder::CreateMemset(Value* dst, |
twisti@2047 | 386 | Value* value, |
twisti@2047 | 387 | Value* len, |
twisti@2047 | 388 | Value* align) { |
twisti@2047 | 389 | return CreateCall5(memset(), dst, value, len, align, |
twisti@2047 | 390 | LLVMValue::jint_constant(0)); |
twisti@2047 | 391 | } |
twisti@2047 | 392 | |
twisti@2047 | 393 | CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) { |
twisti@2047 | 394 | return CreateCall2( |
twisti@2047 | 395 | unimplemented(), |
twisti@2047 | 396 | CreateIntToPtr( |
twisti@2047 | 397 | LLVMValue::intptr_constant((intptr_t) file), |
twisti@2047 | 398 | PointerType::getUnqual(SharkType::jbyte_type())), |
twisti@2047 | 399 | LLVMValue::jint_constant(line)); |
twisti@2047 | 400 | } |
twisti@2047 | 401 | |
twisti@2047 | 402 | CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) { |
twisti@2047 | 403 | return CreateCall2( |
twisti@2047 | 404 | should_not_reach_here(), |
twisti@2047 | 405 | CreateIntToPtr( |
twisti@2047 | 406 | LLVMValue::intptr_constant((intptr_t) file), |
twisti@2047 | 407 | PointerType::getUnqual(SharkType::jbyte_type())), |
twisti@2047 | 408 | LLVMValue::jint_constant(line)); |
twisti@2047 | 409 | } |
twisti@2047 | 410 | |
twisti@2047 | 411 | #ifndef PRODUCT |
twisti@2047 | 412 | CallInst* SharkBuilder::CreateDump(Value* value) { |
twisti@2047 | 413 | const char *name; |
twisti@2047 | 414 | if (value->hasName()) |
twisti@2047 | 415 | // XXX this leaks, but it's only debug code |
twisti@2047 | 416 | name = strdup(value->getName().str().c_str()); |
twisti@2047 | 417 | else |
twisti@2047 | 418 | name = "unnamed_value"; |
twisti@2047 | 419 | |
twisti@2047 | 420 | if (isa<PointerType>(value->getType())) |
twisti@2047 | 421 | value = CreatePtrToInt(value, SharkType::intptr_type()); |
twisti@2047 | 422 | else if (value->getType()-> |
twisti@2047 | 423 | isIntegerTy() |
twisti@2047 | 424 | ) |
twisti@2047 | 425 | value = CreateIntCast(value, SharkType::intptr_type(), false); |
twisti@2047 | 426 | else |
twisti@2047 | 427 | Unimplemented(); |
twisti@2047 | 428 | |
twisti@2047 | 429 | return CreateCall2( |
twisti@2047 | 430 | dump(), |
twisti@2047 | 431 | CreateIntToPtr( |
twisti@2047 | 432 | LLVMValue::intptr_constant((intptr_t) name), |
twisti@2047 | 433 | PointerType::getUnqual(SharkType::jbyte_type())), |
twisti@2047 | 434 | value); |
twisti@2047 | 435 | } |
twisti@2047 | 436 | #endif // PRODUCT |
twisti@2047 | 437 | |
twisti@2047 | 438 | // HotSpot memory barriers |
twisti@2047 | 439 | |
twisti@2047 | 440 | void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) { |
twisti@2047 | 441 | if (bs->kind() != BarrierSet::CardTableModRef) |
twisti@2047 | 442 | Unimplemented(); |
twisti@2047 | 443 | |
twisti@2047 | 444 | CreateStore( |
twisti@2047 | 445 | LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card), |
twisti@2047 | 446 | CreateIntToPtr( |
twisti@2047 | 447 | CreateAdd( |
twisti@2047 | 448 | LLVMValue::intptr_constant( |
twisti@2047 | 449 | (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base), |
twisti@2047 | 450 | CreateLShr( |
twisti@2047 | 451 | CreatePtrToInt(field, SharkType::intptr_type()), |
twisti@2047 | 452 | LLVMValue::intptr_constant(CardTableModRefBS::card_shift))), |
twisti@2047 | 453 | PointerType::getUnqual(SharkType::jbyte_type()))); |
twisti@2047 | 454 | } |
twisti@2047 | 455 | |
twisti@2047 | 456 | // Helpers for accessing the code buffer |
twisti@2047 | 457 | |
twisti@2047 | 458 | Value* SharkBuilder::code_buffer_address(int offset) { |
twisti@2047 | 459 | return CreateAdd( |
twisti@2047 | 460 | code_buffer()->base_pc(), |
twisti@2047 | 461 | LLVMValue::intptr_constant(offset)); |
twisti@2047 | 462 | } |
twisti@2047 | 463 | |
twisti@2047 | 464 | Value* SharkBuilder::CreateInlineOop(jobject object, const char* name) { |
twisti@2047 | 465 | return CreateLoad( |
twisti@2047 | 466 | CreateIntToPtr( |
twisti@2047 | 467 | code_buffer_address(code_buffer()->inline_oop(object)), |
twisti@2047 | 468 | PointerType::getUnqual(SharkType::oop_type())), |
twisti@2047 | 469 | name); |
twisti@2047 | 470 | } |
twisti@2047 | 471 | |
twisti@4314 | 472 | Value* SharkBuilder::CreateInlineMetadata(Metadata* metadata, llvm::PointerType* type, const char* name) { |
twisti@4314 | 473 | assert(metadata != NULL, "inlined metadata must not be NULL"); |
twisti@4314 | 474 | assert(metadata->is_metadata(), "sanity check"); |
twisti@4314 | 475 | return CreateLoad( |
twisti@4314 | 476 | CreateIntToPtr( |
twisti@4314 | 477 | code_buffer_address(code_buffer()->inline_Metadata(metadata)), |
twisti@4314 | 478 | PointerType::getUnqual(type)), |
twisti@4314 | 479 | name); |
twisti@4314 | 480 | } |
twisti@4314 | 481 | |
twisti@2047 | 482 | Value* SharkBuilder::CreateInlineData(void* data, |
twisti@2047 | 483 | size_t size, |
twisti@4314 | 484 | Type* type, |
twisti@2047 | 485 | const char* name) { |
twisti@2047 | 486 | return CreateIntToPtr( |
twisti@2047 | 487 | code_buffer_address(code_buffer()->inline_data(data, size)), |
twisti@2047 | 488 | type, |
twisti@2047 | 489 | name); |
twisti@2047 | 490 | } |
twisti@2047 | 491 | |
twisti@2047 | 492 | // Helpers for creating basic blocks. |
twisti@2047 | 493 | |
twisti@2047 | 494 | BasicBlock* SharkBuilder::GetBlockInsertionPoint() const { |
twisti@2047 | 495 | BasicBlock *cur = GetInsertBlock(); |
twisti@2047 | 496 | |
twisti@2047 | 497 | // BasicBlock::Create takes an insertBefore argument, so |
twisti@2047 | 498 | // we need to find the block _after_ the current block |
twisti@2047 | 499 | Function::iterator iter = cur->getParent()->begin(); |
twisti@2047 | 500 | Function::iterator end = cur->getParent()->end(); |
twisti@2047 | 501 | while (iter != end) { |
twisti@2047 | 502 | iter++; |
twisti@2047 | 503 | if (&*iter == cur) { |
twisti@2047 | 504 | iter++; |
twisti@2047 | 505 | break; |
twisti@2047 | 506 | } |
twisti@2047 | 507 | } |
twisti@2047 | 508 | |
twisti@2047 | 509 | if (iter == end) |
twisti@2047 | 510 | return NULL; |
twisti@2047 | 511 | else |
twisti@2047 | 512 | return iter; |
twisti@2047 | 513 | } |
twisti@2047 | 514 | |
twisti@2047 | 515 | BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const { |
twisti@2047 | 516 | return BasicBlock::Create( |
twisti@2047 | 517 | SharkContext::current(), name, GetInsertBlock()->getParent(), ip); |
twisti@2047 | 518 | } |
twisti@4314 | 519 | |
twisti@4314 | 520 | LoadInst* SharkBuilder::CreateAtomicLoad(Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) { |
twisti@4314 | 521 | return Insert(new LoadInst(ptr, name, isVolatile, align, ordering, synchScope), name); |
twisti@4314 | 522 | } |
twisti@4314 | 523 | |
twisti@4314 | 524 | StoreInst* SharkBuilder::CreateAtomicStore(Value* val, Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) { |
twisti@4314 | 525 | return Insert(new StoreInst(val, ptr, isVolatile, align, ordering, synchScope), name); |
twisti@4314 | 526 | } |