hotspot/src/share/vm/shark/sharkIntrinsics.cpp
author jlaskey
Tue, 23 Jul 2013 12:00:29 -0300
changeset 19089 51cfdcf21d35
parent 14622 8e94e4186d35
child 33606 af4ec8a4635b
permissions -rw-r--r--
8021130: Comments need to be tokens Reviewed-by: lagergren, attila Contributed-by: james.laskey@oracle.com
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 2009 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 "shark/llvmHeaders.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    29
#include "shark/sharkIntrinsics.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    30
#include "shark/sharkState.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    31
#include "shark/sharkValue.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    32
#include "shark/shark_globals.hpp"
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    33
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    34
using namespace llvm;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    35
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    36
bool SharkIntrinsics::is_intrinsic(ciMethod *target) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    37
  switch (target->intrinsic_id()) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    38
  case vmIntrinsics::_none:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    39
    return false;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    40
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    41
    // java.lang.Math
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    42
  case vmIntrinsics::_min:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    43
  case vmIntrinsics::_max:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    44
  case vmIntrinsics::_dabs:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    45
  case vmIntrinsics::_dsin:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    46
  case vmIntrinsics::_dcos:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    47
  case vmIntrinsics::_dtan:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    48
  case vmIntrinsics::_datan2:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    49
  case vmIntrinsics::_dsqrt:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    50
  case vmIntrinsics::_dlog:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    51
  case vmIntrinsics::_dlog10:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    52
  case vmIntrinsics::_dpow:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    53
  case vmIntrinsics::_dexp:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    54
    return true;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    55
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    56
    // java.lang.Object
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    57
  case vmIntrinsics::_getClass:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    58
    return true;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    59
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    60
    // java.lang.System
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    61
  case vmIntrinsics::_currentTimeMillis:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    62
    return true;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    63
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    64
    // java.lang.Thread
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    65
  case vmIntrinsics::_currentThread:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    66
    return true;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    67
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    68
    // sun.misc.Unsafe
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    69
  case vmIntrinsics::_compareAndSwapInt:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    70
    return true;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    71
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    72
  default:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    73
    if (SharkPerformanceWarnings) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    74
      warning(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    75
        "unhandled intrinsic vmIntrinsic::%s",
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    76
        vmIntrinsics::name_at(target->intrinsic_id()));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    77
    }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    78
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    79
  return false;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    80
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    81
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    82
void SharkIntrinsics::inline_intrinsic(ciMethod *target, SharkState *state) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    83
  SharkIntrinsics intrinsic(state, target);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    84
  intrinsic.do_intrinsic();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    85
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    86
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    87
void SharkIntrinsics::do_intrinsic() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    88
  switch (target()->intrinsic_id()) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    89
    // java.lang.Math
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    90
  case vmIntrinsics::_min:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    91
    do_Math_minmax(llvm::ICmpInst::ICMP_SLE);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    92
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    93
  case vmIntrinsics::_max:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    94
    do_Math_minmax(llvm::ICmpInst::ICMP_SGE);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    95
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    96
  case vmIntrinsics::_dabs:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    97
    do_Math_1to1(builder()->fabs());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    98
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
    99
  case vmIntrinsics::_dsin:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   100
    do_Math_1to1(builder()->sin());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   101
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   102
  case vmIntrinsics::_dcos:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   103
    do_Math_1to1(builder()->cos());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   104
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   105
  case vmIntrinsics::_dtan:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   106
    do_Math_1to1(builder()->tan());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   107
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   108
  case vmIntrinsics::_datan2:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   109
    do_Math_2to1(builder()->atan2());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   110
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   111
  case vmIntrinsics::_dsqrt:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   112
    do_Math_1to1(builder()->sqrt());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   113
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   114
  case vmIntrinsics::_dlog:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   115
    do_Math_1to1(builder()->log());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   116
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   117
  case vmIntrinsics::_dlog10:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   118
    do_Math_1to1(builder()->log10());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   119
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   120
  case vmIntrinsics::_dpow:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   121
    do_Math_2to1(builder()->pow());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   122
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   123
  case vmIntrinsics::_dexp:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   124
    do_Math_1to1(builder()->exp());
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   125
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   126
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   127
    // java.lang.Object
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   128
  case vmIntrinsics::_getClass:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   129
    do_Object_getClass();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   130
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   131
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   132
    // java.lang.System
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   133
  case vmIntrinsics::_currentTimeMillis:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   134
    do_System_currentTimeMillis();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   135
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   136
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   137
    // java.lang.Thread
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   138
  case vmIntrinsics::_currentThread:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   139
    do_Thread_currentThread();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   140
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   141
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   142
    // sun.misc.Unsafe
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   143
  case vmIntrinsics::_compareAndSwapInt:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   144
    do_Unsafe_compareAndSwapInt();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   145
    break;
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   146
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   147
  default:
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   148
    ShouldNotReachHere();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   149
  }
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   150
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   151
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   152
void SharkIntrinsics::do_Math_minmax(ICmpInst::Predicate p) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   153
  // Pop the arguments
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   154
  SharkValue *sb = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   155
  SharkValue *sa = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   156
  Value *a = sa->jint_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   157
  Value *b = sb->jint_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   158
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   159
  // Perform the test
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   160
  BasicBlock *ip       = builder()->GetBlockInsertionPoint();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   161
  BasicBlock *return_a = builder()->CreateBlock(ip, "return_a");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   162
  BasicBlock *return_b = builder()->CreateBlock(ip, "return_b");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   163
  BasicBlock *done     = builder()->CreateBlock(ip, "done");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   164
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   165
  builder()->CreateCondBr(builder()->CreateICmp(p, a, b), return_a, return_b);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   166
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   167
  builder()->SetInsertPoint(return_a);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   168
  builder()->CreateBr(done);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   169
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   170
  builder()->SetInsertPoint(return_b);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   171
  builder()->CreateBr(done);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   172
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   173
  builder()->SetInsertPoint(done);
14622
8e94e4186d35 8003868: fix shark for latest HotSpot and LLVM
twisti
parents: 11430
diff changeset
   174
  PHINode *phi = builder()->CreatePHI(a->getType(), 0, "result");
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   175
  phi->addIncoming(a, return_a);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   176
  phi->addIncoming(b, return_b);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   177
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   178
  // Push the result
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   179
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   180
    SharkValue::create_jint(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   181
      phi,
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   182
      sa->zero_checked() && sb->zero_checked()));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   183
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   184
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   185
void SharkIntrinsics::do_Math_1to1(Value *function) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   186
  SharkValue *empty = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   187
  assert(empty == NULL, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   188
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   189
    SharkValue::create_jdouble(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   190
      builder()->CreateCall(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   191
        function, state()->pop()->jdouble_value())));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   192
  state()->push(NULL);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   193
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   194
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   195
void SharkIntrinsics::do_Math_2to1(Value *function) {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   196
  SharkValue *empty = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   197
  assert(empty == NULL, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   198
  Value *y = state()->pop()->jdouble_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   199
  empty = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   200
  assert(empty == NULL, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   201
  Value *x = state()->pop()->jdouble_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   202
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   203
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   204
    SharkValue::create_jdouble(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   205
      builder()->CreateCall2(function, x, y)));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   206
  state()->push(NULL);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   207
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   208
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   209
void SharkIntrinsics::do_Object_getClass() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   210
  Value *klass = builder()->CreateValueOfStructEntry(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   211
    state()->pop()->jobject_value(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   212
    in_ByteSize(oopDesc::klass_offset_in_bytes()),
14622
8e94e4186d35 8003868: fix shark for latest HotSpot and LLVM
twisti
parents: 11430
diff changeset
   213
    SharkType::klass_type(),
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   214
    "klass");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   215
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   216
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   217
    SharkValue::create_jobject(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   218
      builder()->CreateValueOfStructEntry(
11430
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 7397
diff changeset
   219
        klass,
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 7397
diff changeset
   220
        Klass::java_mirror_offset(),
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   221
        SharkType::oop_type(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   222
        "java_mirror"),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   223
      true));
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
void SharkIntrinsics::do_System_currentTimeMillis() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   227
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   228
    SharkValue::create_jlong(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   229
      builder()->CreateCall(builder()->current_time_millis()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   230
      false));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   231
  state()->push(NULL);
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
void SharkIntrinsics::do_Thread_currentThread() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   235
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   236
    SharkValue::create_jobject(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   237
      builder()->CreateValueOfStructEntry(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   238
        thread(), JavaThread::threadObj_offset(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   239
        SharkType::oop_type(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   240
        "threadObj"),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   241
      true));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   242
}
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   243
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   244
void SharkIntrinsics::do_Unsafe_compareAndSwapInt() {
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   245
  // Pop the arguments
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   246
  Value *x      = state()->pop()->jint_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   247
  Value *e      = state()->pop()->jint_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   248
  SharkValue *empty = state()->pop();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   249
  assert(empty == NULL, "should be");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   250
  Value *offset = state()->pop()->jlong_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   251
  Value *object = state()->pop()->jobject_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   252
  Value *unsafe = state()->pop()->jobject_value();
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   253
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   254
  // Convert the offset
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   255
  offset = builder()->CreateCall(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   256
    builder()->unsafe_field_offset_to_byte_offset(),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   257
    offset);
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   258
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   259
  // Locate the field
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   260
  Value *addr = builder()->CreateIntToPtr(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   261
    builder()->CreateAdd(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   262
      builder()->CreatePtrToInt(object, SharkType::intptr_type()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   263
      builder()->CreateIntCast(offset, SharkType::intptr_type(), true)),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   264
    PointerType::getUnqual(SharkType::jint_type()),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   265
    "addr");
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   266
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   267
  // Perform the operation
14622
8e94e4186d35 8003868: fix shark for latest HotSpot and LLVM
twisti
parents: 11430
diff changeset
   268
  Value *result = builder()->CreateAtomicCmpXchg(addr, e, x, llvm::SequentiallyConsistent);
6187
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   269
  // Push the result
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   270
  state()->push(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   271
    SharkValue::create_jint(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   272
      builder()->CreateIntCast(
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   273
        builder()->CreateICmpEQ(result, e), SharkType::jint_type(), true),
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   274
      false));
4fa7845f7c14 6976186: integrate Shark HotSpot changes
twisti
parents:
diff changeset
   275
}