hotspot/src/share/vm/shark/sharkBuilder.cpp
author stefank
Tue, 23 Nov 2010 13:22:55 -0800
changeset 7397 5b173b4ca846
parent 6187 4fa7845f7c14
child 13728 882756847a04
permissions -rw-r--r--
6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     3
 * Copyright 2008, 2009, 2010 Red Hat, Inc.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     5
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     8
 * published by the Free Software Foundation.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
     9
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    14
 * accompanied this code).
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    15
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    19
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    22
 * questions.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    23
 *
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    24
 */
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    25
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    26
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    27
#include "ci/ciMethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    29
#include "oops/methodOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    30
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    31
#include "runtime/synchronizer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    32
#include "runtime/thread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    33
#include "shark/llvmHeaders.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    34
#include "shark/llvmValue.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    35
#include "shark/sharkBuilder.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    36
#include "shark/sharkContext.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    37
#include "shark/sharkRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    38
#include "utilities/debug.hpp"
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    39
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    40
using namespace llvm;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    41
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    42
SharkBuilder::SharkBuilder(SharkCodeBuffer* code_buffer)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    43
  : IRBuilder<>(SharkContext::current()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    44
    _code_buffer(code_buffer) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    45
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    46
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    47
// Helpers for accessing structures
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    48
Value* SharkBuilder::CreateAddressOfStructEntry(Value*      base,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    49
                                                ByteSize    offset,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    50
                                                const Type* type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    51
                                                const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    52
  return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    53
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    54
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    55
LoadInst* SharkBuilder::CreateValueOfStructEntry(Value*      base,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    56
                                                 ByteSize    offset,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    57
                                                 const Type* type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    58
                                                 const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    59
  return CreateLoad(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    60
    CreateAddressOfStructEntry(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    61
      base, offset, PointerType::getUnqual(type)),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    62
    name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    63
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    64
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    65
// Helpers for accessing arrays
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    66
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    67
LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    68
  return CreateValueOfStructEntry(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    69
    arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    70
    SharkType::jint_type(), "length");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    71
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    72
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    73
Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    74
                                        const Type* element_type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    75
                                        int         element_bytes,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    76
                                        ByteSize    base_offset,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    77
                                        Value*      index,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    78
                                        const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    79
  Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    80
  if (element_bytes != 1)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    81
    offset = CreateShl(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    82
      offset,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    83
      LLVMValue::intptr_constant(exact_log2(element_bytes)));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    84
  offset = CreateAdd(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    85
    LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    86
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    87
  return CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    88
    CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    89
    PointerType::getUnqual(element_type),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    90
    name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    91
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    92
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    93
Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    94
                                        BasicType   basic_type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    95
                                        ByteSize    base_offset,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    96
                                        Value*      index,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    97
                                        const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    98
  return CreateArrayAddress(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    99
    arrayoop,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   100
    SharkType::to_arrayType(basic_type),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   101
    type2aelembytes(basic_type),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   102
    base_offset, index, name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   103
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   104
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   105
Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   106
                                        BasicType   basic_type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   107
                                        Value*      index,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   108
                                        const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   109
  return CreateArrayAddress(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   110
    arrayoop, basic_type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   111
    in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   112
    index, name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   113
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   114
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   115
// Helpers for creating intrinsics and external functions.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   116
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   117
const Type* SharkBuilder::make_type(char type, bool void_ok) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   118
  switch (type) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   119
    // Primitive types
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   120
  case 'c':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   121
    return SharkType::jbyte_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   122
  case 'i':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   123
    return SharkType::jint_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   124
  case 'l':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   125
    return SharkType::jlong_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   126
  case 'x':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   127
    return SharkType::intptr_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   128
  case 'f':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   129
    return SharkType::jfloat_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   130
  case 'd':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   131
    return SharkType::jdouble_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   132
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   133
    // Pointers to primitive types
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   134
  case 'C':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   135
  case 'I':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   136
  case 'L':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   137
  case 'X':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   138
  case 'F':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   139
  case 'D':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   140
    return PointerType::getUnqual(make_type(tolower(type), false));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   141
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   142
    // VM objects
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   143
  case 'T':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   144
    return SharkType::thread_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   145
  case 'M':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   146
    return PointerType::getUnqual(SharkType::monitor_type());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   147
  case 'O':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   148
    return SharkType::oop_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   149
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   150
    // Miscellaneous
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   151
  case 'v':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   152
    assert(void_ok, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   153
    return SharkType::void_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   154
  case '1':
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   155
    return SharkType::bit_type();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   156
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   157
  default:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   158
    ShouldNotReachHere();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   159
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   160
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   161
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   162
const FunctionType* SharkBuilder::make_ftype(const char* params,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   163
                                             const char* ret) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   164
  std::vector<const Type*> param_types;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   165
  for (const char* c = params; *c; c++)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   166
    param_types.push_back(make_type(*c, false));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   167
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   168
  assert(strlen(ret) == 1, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   169
  const Type *return_type = make_type(*ret, true);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   170
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   171
  return FunctionType::get(return_type, param_types, false);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   172
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   173
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   174
// Create an object representing an intrinsic or external function by
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   175
// referencing the symbol by name.  This is the LLVM-style approach,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   176
// but it cannot be used on functions within libjvm.so its symbols
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   177
// are not exported.  Note that you cannot make this work simply by
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   178
// exporting the symbols, as some symbols have the same names as
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   179
// symbols in the standard libraries (eg, atan2, fabs) and would
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   180
// obscure them were they visible.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   181
Value* SharkBuilder::make_function(const char* name,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   182
                                   const char* params,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   183
                                   const char* ret) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   184
  return SharkContext::current().get_external(name, make_ftype(params, ret));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   185
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   186
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   187
// Create an object representing an external function by inlining a
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   188
// function pointer in the code.  This is not the LLVM way, but it's
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   189
// the only way to access functions in libjvm.so and functions like
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   190
// __kernel_dmb on ARM which is accessed via an absolute address.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   191
Value* SharkBuilder::make_function(address     func,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   192
                                   const char* params,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   193
                                   const char* ret) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   194
  return CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   195
    LLVMValue::intptr_constant((intptr_t) func),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   196
    PointerType::getUnqual(make_ftype(params, ret)));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   197
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   198
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   199
// VM calls
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   200
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   201
Value* SharkBuilder::find_exception_handler() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   202
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   203
    (address) SharkRuntime::find_exception_handler, "TIi", "i");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   204
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   205
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   206
Value* SharkBuilder::monitorenter() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   207
  return make_function((address) SharkRuntime::monitorenter, "TM", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   208
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   209
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   210
Value* SharkBuilder::monitorexit() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   211
  return make_function((address) SharkRuntime::monitorexit, "TM", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   212
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   213
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   214
Value* SharkBuilder::new_instance() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   215
  return make_function((address) SharkRuntime::new_instance, "Ti", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   216
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   217
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   218
Value* SharkBuilder::newarray() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   219
  return make_function((address) SharkRuntime::newarray, "Tii", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   220
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   221
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   222
Value* SharkBuilder::anewarray() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   223
  return make_function((address) SharkRuntime::anewarray, "Tii", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   224
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   225
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   226
Value* SharkBuilder::multianewarray() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   227
  return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   228
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   229
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   230
Value* SharkBuilder::register_finalizer() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   231
  return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   232
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   233
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   234
Value* SharkBuilder::safepoint() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   235
  return make_function((address) SafepointSynchronize::block, "T", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   236
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   237
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   238
Value* SharkBuilder::throw_ArithmeticException() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   239
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   240
    (address) SharkRuntime::throw_ArithmeticException, "TCi", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   241
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   242
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   243
Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   244
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   245
    (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   246
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   247
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   248
Value* SharkBuilder::throw_ClassCastException() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   249
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   250
    (address) SharkRuntime::throw_ClassCastException, "TCi", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   251
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   252
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   253
Value* SharkBuilder::throw_NullPointerException() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   254
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   255
    (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   256
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   257
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   258
// High-level non-VM calls
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   259
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   260
Value* SharkBuilder::f2i() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   261
  return make_function((address) SharedRuntime::f2i, "f", "i");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   262
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   263
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   264
Value* SharkBuilder::f2l() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   265
  return make_function((address) SharedRuntime::f2l, "f", "l");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   266
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   267
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   268
Value* SharkBuilder::d2i() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   269
  return make_function((address) SharedRuntime::d2i, "d", "i");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   270
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   271
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   272
Value* SharkBuilder::d2l() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   273
  return make_function((address) SharedRuntime::d2l, "d", "l");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   274
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   275
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   276
Value* SharkBuilder::is_subtype_of() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   277
  return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   278
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   279
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   280
Value* SharkBuilder::current_time_millis() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   281
  return make_function((address) os::javaTimeMillis, "", "l");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   282
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   283
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   284
Value* SharkBuilder::sin() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   285
  return make_function("llvm.sin.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   286
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   287
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   288
Value* SharkBuilder::cos() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   289
  return make_function("llvm.cos.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   290
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   291
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   292
Value* SharkBuilder::tan() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   293
  return make_function((address) ::tan, "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   294
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   295
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   296
Value* SharkBuilder::atan2() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   297
  return make_function((address) ::atan2, "dd", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   298
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   299
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   300
Value* SharkBuilder::sqrt() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   301
  return make_function("llvm.sqrt.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   302
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   303
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   304
Value* SharkBuilder::log() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   305
  return make_function("llvm.log.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   306
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   307
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   308
Value* SharkBuilder::log10() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   309
  return make_function("llvm.log10.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   310
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   311
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   312
Value* SharkBuilder::pow() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   313
  return make_function("llvm.pow.f64", "dd", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   314
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   315
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   316
Value* SharkBuilder::exp() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   317
  return make_function("llvm.exp.f64", "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   318
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   319
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   320
Value* SharkBuilder::fabs() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   321
  return make_function((address) ::fabs, "d", "d");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   322
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   323
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   324
Value* SharkBuilder::unsafe_field_offset_to_byte_offset() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   325
  extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   326
  return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   327
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   328
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   329
Value* SharkBuilder::osr_migration_end() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   330
  return make_function((address) SharedRuntime::OSR_migration_end, "C", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   331
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   332
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   333
// Semi-VM calls
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   334
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   335
Value* SharkBuilder::throw_StackOverflowError() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   336
  return make_function((address) ZeroStack::handle_overflow, "T", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   337
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   338
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   339
Value* SharkBuilder::uncommon_trap() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   340
  return make_function((address) SharkRuntime::uncommon_trap, "Ti", "i");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   341
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   342
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   343
Value* SharkBuilder::deoptimized_entry_point() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   344
  return make_function((address) CppInterpreter::main_loop, "iT", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   345
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   346
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   347
// Native-Java transition
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   348
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   349
Value* SharkBuilder::check_special_condition_for_native_trans() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   350
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   351
    (address) JavaThread::check_special_condition_for_native_trans,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   352
    "T", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   353
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   354
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   355
// Low-level non-VM calls
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   356
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   357
// The ARM-specific code here is to work around unimplemented
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   358
// atomic exchange and memory barrier intrinsics in LLVM.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   359
//
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   360
// Delegating to external functions for these would normally
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   361
// incur a speed penalty, but Linux on ARM is a special case
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   362
// in that atomic operations on that platform are handled by
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   363
// external functions anyway.  It would be *preferable* for
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   364
// the calls to be hidden away in LLVM, but it's not hurting
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   365
// performance so having the calls here is acceptable.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   366
//
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   367
// If you are building Shark on a platform without atomic
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   368
// exchange and/or memory barrier intrinsics then it is only
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   369
// acceptable to mimic this approach if your platform cannot
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   370
// perform these operations without delegating to a function.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   371
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   372
#ifdef ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   373
static jint zero_cmpxchg_int(volatile jint *ptr, jint oldval, jint newval) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   374
  return Atomic::cmpxchg(newval, ptr, oldval);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   375
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   376
#endif // ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   377
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   378
Value* SharkBuilder::cmpxchg_int() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   379
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   380
#ifdef ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   381
    (address) zero_cmpxchg_int,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   382
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   383
    "llvm.atomic.cmp.swap.i32.p0i32",
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   384
#endif // ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   385
    "Iii", "i");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   386
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   387
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   388
#ifdef ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   389
static intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   390
                                 intptr_t           oldval,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   391
                                 intptr_t           newval) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   392
  return Atomic::cmpxchg_ptr(newval, ptr, oldval);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   393
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   394
#endif // ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   395
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   396
Value* SharkBuilder::cmpxchg_ptr() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   397
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   398
#ifdef ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   399
    (address) zero_cmpxchg_ptr,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   400
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   401
    "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32") ".p0i" LP64_ONLY("64") NOT_LP64("32"),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   402
#endif // ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   403
    "Xxx", "x");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   404
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   405
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   406
Value* SharkBuilder::frame_address() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   407
  return make_function("llvm.frameaddress", "i", "C");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   408
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   409
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   410
Value* SharkBuilder::memory_barrier() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   411
  return make_function(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   412
#ifdef ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   413
    (address) 0xffff0fa0, // __kernel_dmb
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   414
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   415
    "llvm.memory.barrier",
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   416
#endif // ARM
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   417
    "11111", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   418
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   419
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   420
Value* SharkBuilder::memset() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   421
#if SHARK_LLVM_VERSION >= 28
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   422
  // LLVM 2.8 added a fifth isVolatile field for memset
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   423
  // introduced with LLVM r100304
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   424
  return make_function("llvm.memset.i32", "Cciii", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   425
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   426
  return make_function("llvm.memset.i32", "Ccii", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   427
#endif
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   428
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   429
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   430
Value* SharkBuilder::unimplemented() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   431
  return make_function((address) report_unimplemented, "Ci", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   432
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   433
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   434
Value* SharkBuilder::should_not_reach_here() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   435
  return make_function((address) report_should_not_reach_here, "Ci", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   436
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   437
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   438
Value* SharkBuilder::dump() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   439
  return make_function((address) SharkRuntime::dump, "Cx", "v");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   440
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   441
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   442
// Public interface to low-level non-VM calls
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   443
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   444
CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   445
                                         Value* dst,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   446
                                         Value* compare_value) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   447
  return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   448
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   449
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   450
CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   451
                                         Value* dst,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   452
                                         Value* compare_value) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   453
  return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   454
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   455
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   456
CallInst* SharkBuilder::CreateGetFrameAddress() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   457
  return CreateCall(frame_address(), LLVMValue::jint_constant(0));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   458
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   459
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   460
CallInst *SharkBuilder::CreateMemoryBarrier(int flags) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   461
  Value *args[] = {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   462
    LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   463
    LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   464
    LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   465
    LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   466
    LLVMValue::bit_constant(1)};
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   467
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   468
  return CreateCall(memory_barrier(), args, args + 5);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   469
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   470
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   471
CallInst* SharkBuilder::CreateMemset(Value* dst,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   472
                                     Value* value,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   473
                                     Value* len,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   474
                                     Value* align) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   475
#if SHARK_LLVM_VERSION >= 28
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   476
  return CreateCall5(memset(), dst, value, len, align,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   477
                     LLVMValue::jint_constant(0));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   478
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   479
  return CreateCall4(memset(), dst, value, len, align);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   480
#endif
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   481
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   482
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   483
CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   484
  return CreateCall2(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   485
    unimplemented(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   486
    CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   487
      LLVMValue::intptr_constant((intptr_t) file),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   488
      PointerType::getUnqual(SharkType::jbyte_type())),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   489
    LLVMValue::jint_constant(line));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   490
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   491
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   492
CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   493
  return CreateCall2(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   494
    should_not_reach_here(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   495
    CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   496
      LLVMValue::intptr_constant((intptr_t) file),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   497
      PointerType::getUnqual(SharkType::jbyte_type())),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   498
    LLVMValue::jint_constant(line));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   499
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   500
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   501
#ifndef PRODUCT
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   502
CallInst* SharkBuilder::CreateDump(Value* value) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   503
  const char *name;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   504
  if (value->hasName())
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   505
    // XXX this leaks, but it's only debug code
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   506
    name = strdup(value->getName().str().c_str());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   507
  else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   508
    name = "unnamed_value";
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   509
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   510
  if (isa<PointerType>(value->getType()))
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   511
    value = CreatePtrToInt(value, SharkType::intptr_type());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   512
  else if (value->getType()->
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   513
#if SHARK_LLVM_VERSION >= 27
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   514
           isIntegerTy()
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   515
#else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   516
           isInteger()
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   517
#endif
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   518
           )
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   519
    value = CreateIntCast(value, SharkType::intptr_type(), false);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   520
  else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   521
    Unimplemented();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   522
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   523
  return CreateCall2(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   524
    dump(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   525
    CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   526
      LLVMValue::intptr_constant((intptr_t) name),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   527
      PointerType::getUnqual(SharkType::jbyte_type())),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   528
    value);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   529
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   530
#endif // PRODUCT
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   531
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   532
// HotSpot memory barriers
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   533
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   534
void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   535
  if (bs->kind() != BarrierSet::CardTableModRef)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   536
    Unimplemented();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   537
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   538
  CreateStore(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   539
    LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   540
    CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   541
      CreateAdd(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   542
        LLVMValue::intptr_constant(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   543
          (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   544
        CreateLShr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   545
          CreatePtrToInt(field, SharkType::intptr_type()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   546
          LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   547
      PointerType::getUnqual(SharkType::jbyte_type())));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   548
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   549
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   550
// Helpers for accessing the code buffer
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   551
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   552
Value* SharkBuilder::code_buffer_address(int offset) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   553
  return CreateAdd(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   554
    code_buffer()->base_pc(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   555
    LLVMValue::intptr_constant(offset));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   556
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   557
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   558
Value* SharkBuilder::CreateInlineOop(jobject object, const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   559
  return CreateLoad(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   560
    CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   561
      code_buffer_address(code_buffer()->inline_oop(object)),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   562
      PointerType::getUnqual(SharkType::oop_type())),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   563
    name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   564
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   565
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   566
Value* SharkBuilder::CreateInlineData(void*       data,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   567
                                      size_t      size,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   568
                                      const Type* type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   569
                                      const char* name) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   570
  return CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   571
    code_buffer_address(code_buffer()->inline_data(data, size)),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   572
    type,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   573
    name);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   574
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   575
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   576
// Helpers for creating basic blocks.
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   577
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   578
BasicBlock* SharkBuilder::GetBlockInsertionPoint() const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   579
  BasicBlock *cur = GetInsertBlock();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   580
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   581
  // BasicBlock::Create takes an insertBefore argument, so
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   582
  // we need to find the block _after_ the current block
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   583
  Function::iterator iter = cur->getParent()->begin();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   584
  Function::iterator end  = cur->getParent()->end();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   585
  while (iter != end) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   586
    iter++;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   587
    if (&*iter == cur) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   588
      iter++;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   589
      break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   590
    }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   591
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   592
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   593
  if (iter == end)
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   594
    return NULL;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   595
  else
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   596
    return iter;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   597
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   598
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   599
BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   600
  return BasicBlock::Create(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   601
    SharkContext::current(), name, GetInsertBlock()->getParent(), ip);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   602
}