src/share/vm/shark/sharkBuilder.cpp

changeset 4314
2cd5e15048e6
parent 4037
da91efe96a93
child 5307
e0c9a1d29eb4
     1.1 --- a/src/share/vm/shark/sharkBuilder.cpp	Mon Nov 26 17:25:11 2012 -0800
     1.2 +++ b/src/share/vm/shark/sharkBuilder.cpp	Tue Nov 27 12:48:52 2012 -0800
     1.3 @@ -47,14 +47,14 @@
     1.4  // Helpers for accessing structures
     1.5  Value* SharkBuilder::CreateAddressOfStructEntry(Value*      base,
     1.6                                                  ByteSize    offset,
     1.7 -                                                const Type* type,
     1.8 +                                                Type* type,
     1.9                                                  const char* name) {
    1.10    return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
    1.11  }
    1.12  
    1.13  LoadInst* SharkBuilder::CreateValueOfStructEntry(Value*      base,
    1.14                                                   ByteSize    offset,
    1.15 -                                                 const Type* type,
    1.16 +                                                 Type* type,
    1.17                                                   const char* name) {
    1.18    return CreateLoad(
    1.19      CreateAddressOfStructEntry(
    1.20 @@ -71,7 +71,7 @@
    1.21  }
    1.22  
    1.23  Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
    1.24 -                                        const Type* element_type,
    1.25 +                                        Type* element_type,
    1.26                                          int         element_bytes,
    1.27                                          ByteSize    base_offset,
    1.28                                          Value*      index,
    1.29 @@ -114,7 +114,7 @@
    1.30  
    1.31  // Helpers for creating intrinsics and external functions.
    1.32  
    1.33 -const Type* SharkBuilder::make_type(char type, bool void_ok) {
    1.34 +Type* SharkBuilder::make_type(char type, bool void_ok) {
    1.35    switch (type) {
    1.36      // Primitive types
    1.37    case 'c':
    1.38 @@ -146,6 +146,8 @@
    1.39      return PointerType::getUnqual(SharkType::monitor_type());
    1.40    case 'O':
    1.41      return SharkType::oop_type();
    1.42 +  case 'K':
    1.43 +    return SharkType::klass_type();
    1.44  
    1.45      // Miscellaneous
    1.46    case 'v':
    1.47 @@ -159,14 +161,14 @@
    1.48    }
    1.49  }
    1.50  
    1.51 -const FunctionType* SharkBuilder::make_ftype(const char* params,
    1.52 +FunctionType* SharkBuilder::make_ftype(const char* params,
    1.53                                               const char* ret) {
    1.54 -  std::vector<const Type*> param_types;
    1.55 +  std::vector<Type*> param_types;
    1.56    for (const char* c = params; *c; c++)
    1.57      param_types.push_back(make_type(*c, false));
    1.58  
    1.59    assert(strlen(ret) == 1, "should be");
    1.60 -  const Type *return_type = make_type(*ret, true);
    1.61 +  Type *return_type = make_type(*ret, true);
    1.62  
    1.63    return FunctionType::get(return_type, param_types, false);
    1.64  }
    1.65 @@ -274,7 +276,7 @@
    1.66  }
    1.67  
    1.68  Value* SharkBuilder::is_subtype_of() {
    1.69 -  return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
    1.70 +  return make_function((address) SharkRuntime::is_subtype_of, "KK", "c");
    1.71  }
    1.72  
    1.73  Value* SharkBuilder::current_time_millis() {
    1.74 @@ -352,79 +354,14 @@
    1.75      "T", "v");
    1.76  }
    1.77  
    1.78 -// Low-level non-VM calls
    1.79 -
    1.80 -// The ARM-specific code here is to work around unimplemented
    1.81 -// atomic exchange and memory barrier intrinsics in LLVM.
    1.82 -//
    1.83 -// Delegating to external functions for these would normally
    1.84 -// incur a speed penalty, but Linux on ARM is a special case
    1.85 -// in that atomic operations on that platform are handled by
    1.86 -// external functions anyway.  It would be *preferable* for
    1.87 -// the calls to be hidden away in LLVM, but it's not hurting
    1.88 -// performance so having the calls here is acceptable.
    1.89 -//
    1.90 -// If you are building Shark on a platform without atomic
    1.91 -// exchange and/or memory barrier intrinsics then it is only
    1.92 -// acceptable to mimic this approach if your platform cannot
    1.93 -// perform these operations without delegating to a function.
    1.94 -
    1.95 -#ifdef ARM
    1.96 -static jint zero_cmpxchg_int(volatile jint *ptr, jint oldval, jint newval) {
    1.97 -  return Atomic::cmpxchg(newval, ptr, oldval);
    1.98 -}
    1.99 -#endif // ARM
   1.100 -
   1.101 -Value* SharkBuilder::cmpxchg_int() {
   1.102 -  return make_function(
   1.103 -#ifdef ARM
   1.104 -    (address) zero_cmpxchg_int,
   1.105 -#else
   1.106 -    "llvm.atomic.cmp.swap.i32.p0i32",
   1.107 -#endif // ARM
   1.108 -    "Iii", "i");
   1.109 -}
   1.110 -
   1.111 -#ifdef ARM
   1.112 -static intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
   1.113 -                                 intptr_t           oldval,
   1.114 -                                 intptr_t           newval) {
   1.115 -  return Atomic::cmpxchg_ptr(newval, ptr, oldval);
   1.116 -}
   1.117 -#endif // ARM
   1.118 -
   1.119 -Value* SharkBuilder::cmpxchg_ptr() {
   1.120 -  return make_function(
   1.121 -#ifdef ARM
   1.122 -    (address) zero_cmpxchg_ptr,
   1.123 -#else
   1.124 -    "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32") ".p0i" LP64_ONLY("64") NOT_LP64("32"),
   1.125 -#endif // ARM
   1.126 -    "Xxx", "x");
   1.127 -}
   1.128 -
   1.129  Value* SharkBuilder::frame_address() {
   1.130    return make_function("llvm.frameaddress", "i", "C");
   1.131  }
   1.132  
   1.133 -Value* SharkBuilder::memory_barrier() {
   1.134 -  return make_function(
   1.135 -#ifdef ARM
   1.136 -    (address) 0xffff0fa0, // __kernel_dmb
   1.137 -#else
   1.138 -    "llvm.memory.barrier",
   1.139 -#endif // ARM
   1.140 -    "11111", "v");
   1.141 -}
   1.142 -
   1.143  Value* SharkBuilder::memset() {
   1.144 -#if SHARK_LLVM_VERSION >= 28
   1.145    // LLVM 2.8 added a fifth isVolatile field for memset
   1.146    // introduced with LLVM r100304
   1.147 -  return make_function("llvm.memset.i32", "Cciii", "v");
   1.148 -#else
   1.149 -  return make_function("llvm.memset.i32", "Ccii", "v");
   1.150 -#endif
   1.151 +  return make_function("llvm.memset.p0i8.i32", "Cciii", "v");
   1.152  }
   1.153  
   1.154  Value* SharkBuilder::unimplemented() {
   1.155 @@ -441,43 +378,16 @@
   1.156  
   1.157  // Public interface to low-level non-VM calls
   1.158  
   1.159 -CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
   1.160 -                                         Value* dst,
   1.161 -                                         Value* compare_value) {
   1.162 -  return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
   1.163 -}
   1.164 -
   1.165 -CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
   1.166 -                                         Value* dst,
   1.167 -                                         Value* compare_value) {
   1.168 -  return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
   1.169 -}
   1.170 -
   1.171  CallInst* SharkBuilder::CreateGetFrameAddress() {
   1.172    return CreateCall(frame_address(), LLVMValue::jint_constant(0));
   1.173  }
   1.174  
   1.175 -CallInst *SharkBuilder::CreateMemoryBarrier(int flags) {
   1.176 -  Value *args[] = {
   1.177 -    LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
   1.178 -    LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
   1.179 -    LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
   1.180 -    LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
   1.181 -    LLVMValue::bit_constant(1)};
   1.182 -
   1.183 -  return CreateCall(memory_barrier(), args, args + 5);
   1.184 -}
   1.185 -
   1.186  CallInst* SharkBuilder::CreateMemset(Value* dst,
   1.187                                       Value* value,
   1.188                                       Value* len,
   1.189                                       Value* align) {
   1.190 -#if SHARK_LLVM_VERSION >= 28
   1.191    return CreateCall5(memset(), dst, value, len, align,
   1.192                       LLVMValue::jint_constant(0));
   1.193 -#else
   1.194 -  return CreateCall4(memset(), dst, value, len, align);
   1.195 -#endif
   1.196  }
   1.197  
   1.198  CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
   1.199 @@ -510,11 +420,7 @@
   1.200    if (isa<PointerType>(value->getType()))
   1.201      value = CreatePtrToInt(value, SharkType::intptr_type());
   1.202    else if (value->getType()->
   1.203 -#if SHARK_LLVM_VERSION >= 27
   1.204             isIntegerTy()
   1.205 -#else
   1.206 -           isInteger()
   1.207 -#endif
   1.208             )
   1.209      value = CreateIntCast(value, SharkType::intptr_type(), false);
   1.210    else
   1.211 @@ -563,9 +469,19 @@
   1.212      name);
   1.213  }
   1.214  
   1.215 +Value* SharkBuilder::CreateInlineMetadata(Metadata* metadata, llvm::PointerType* type, const char* name) {
   1.216 +  assert(metadata != NULL, "inlined metadata must not be NULL");
   1.217 +  assert(metadata->is_metadata(), "sanity check");
   1.218 +  return CreateLoad(
   1.219 +    CreateIntToPtr(
   1.220 +      code_buffer_address(code_buffer()->inline_Metadata(metadata)),
   1.221 +      PointerType::getUnqual(type)),
   1.222 +    name);
   1.223 +}
   1.224 +
   1.225  Value* SharkBuilder::CreateInlineData(void*       data,
   1.226                                        size_t      size,
   1.227 -                                      const Type* type,
   1.228 +                                      Type* type,
   1.229                                        const char* name) {
   1.230    return CreateIntToPtr(
   1.231      code_buffer_address(code_buffer()->inline_data(data, size)),
   1.232 @@ -600,3 +516,11 @@
   1.233    return BasicBlock::Create(
   1.234      SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
   1.235  }
   1.236 +
   1.237 +LoadInst* SharkBuilder::CreateAtomicLoad(Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) {
   1.238 +  return Insert(new LoadInst(ptr, name, isVolatile, align, ordering, synchScope), name);
   1.239 +}
   1.240 +
   1.241 +StoreInst* SharkBuilder::CreateAtomicStore(Value* val, Value* ptr, unsigned align, AtomicOrdering ordering, SynchronizationScope synchScope, bool isVolatile, const char* name) {
   1.242 +  return Insert(new StoreInst(val, ptr, isVolatile, align, ordering, synchScope), name);
   1.243 +}

mercurial