hotspot/src/share/vm/jvmci/jvmciCompiler.cpp
author neliasso
Wed, 13 Apr 2016 14:48:22 +0200
changeset 38218 f5ba1dea04eb
parent 37248 11a660dbbb8e
child 38666 5ff19807abd5
permissions -rw-r--r--
8153013: BlockingCompilation test times out Summary: Task has no invocation count and get stale at once Reviewed-by: kvn, iveresov, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 36612
diff changeset
     2
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
#include "precompiled.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
#include "memory/oopFactory.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 36612
diff changeset
    26
#include "memory/resourceArea.hpp"
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
#include "oops/oop.inline.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
#include "runtime/javaCalls.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    29
#include "runtime/handles.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    30
#include "jvmci/jvmciJavaClasses.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    31
#include "jvmci/jvmciCompiler.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    32
#include "jvmci/jvmciEnv.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    33
#include "jvmci/jvmciRuntime.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    34
#include "runtime/compilationPolicy.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    35
#include "runtime/globals_extension.hpp"
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    37
JVMCICompiler* JVMCICompiler::_instance = NULL;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    38
elapsedTimer JVMCICompiler::_codeInstallTimer;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    41
  _bootstrapping = false;
35845
30025047885d 8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents: 35592
diff changeset
    42
  _methods_compiled = 0;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
  assert(_instance == NULL, "only one instance allowed");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
  _instance = this;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    45
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
// Initialization
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
void JVMCICompiler::initialize() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
  if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
    return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
  set_state(initialized);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
  // JVMCI is considered as application code so we need to
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
  // stop the VM deferring compilation now.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
  CompilationPolicy::completed_vm_startup();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
void JVMCICompiler::bootstrap() {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
    61
  if (Arguments::mode() == Arguments::_int) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
    62
    // Nothing to do in -Xint mode
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
    63
    return;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
    64
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
#ifndef PRODUCT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
  // We turn off CompileTheWorld so that compilation requests are not
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
  // ignored during bootstrap or that JVMCI can be compiled by C1/C2.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
  FlagSetting ctwOff(CompileTheWorld, false);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
#endif
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
  JavaThread* THREAD = JavaThread::current();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
  _bootstrapping = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
  ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
  HandleMark hm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
  if (PrintBootstrap) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
    tty->print("Bootstrapping JVMCI");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
  jlong start = os::javaTimeMillis();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33160
diff changeset
    80
  Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
  // Initialize compile queue with a selected set of methods.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
  int len = objectMethods->length();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
  for (int i = 0; i < len; i++) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
    methodHandle mh = objectMethods->at(i);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
    if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
      ResourceMark rm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
      int hot_count = 10; // TODO: what's the appropriate value?
38218
f5ba1dea04eb 8153013: BlockingCompilation test times out
neliasso
parents: 37248
diff changeset
    88
      CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
  int qsize;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
  bool first_round = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
  int z = 0;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
  do {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
    // Loop until there is something in the queue.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
    do {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
      os::sleep(THREAD, 100, true);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
      qsize = CompileBroker::queue_size(CompLevel_full_optimization);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
    } while (first_round && qsize == 0);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
    first_round = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
    if (PrintBootstrap) {
35845
30025047885d 8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents: 35592
diff changeset
   103
      while (z < (_methods_compiled / 100)) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
        ++z;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
        tty->print_raw(".");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
      }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
  } while (qsize != 0);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   109
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   110
  if (PrintBootstrap) {
35845
30025047885d 8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents: 35592
diff changeset
   111
    tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   112
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   113
  _bootstrapping = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   114
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   115
35143
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   116
#define CHECK_ABORT THREAD); \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   117
if (HAS_PENDING_EXCEPTION) { \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   118
  char buf[256]; \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   119
  jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   120
  JVMCICompiler::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   121
  return; \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   122
} \
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   123
(void)(0
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   124
34165
66826441022f 8142329: [JVMCI] pass Handle by value
twisti
parents: 33632
diff changeset
   125
void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   126
  JVMCI_EXCEPTION_CONTEXT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   127
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   128
  bool is_osr = entry_bci != InvocationEntryBci;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   129
  if (_bootstrapping && is_osr) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   130
      // no OSR compilations during bootstrap - the compiler is just too slow at this point,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
      // and we know that there are no endless loops
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
      return;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   133
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
  JVMCIRuntime::initialize_well_known_classes(CHECK_ABORT);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   136
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
  HandleMark hm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   138
  Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_ABORT);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   139
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   140
  JavaValue method_result(T_OBJECT);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   141
  JavaCallArguments args;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   142
  args.push_long((jlong) (address) method());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   143
  JavaCalls::call_static(&method_result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(),
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   144
                         vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, THREAD);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   145
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   146
  JavaValue result(T_OBJECT);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   147
  if (!HAS_PENDING_EXCEPTION) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   148
    JavaCallArguments args;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   149
    args.push_oop(receiver);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   150
    args.push_oop((oop)method_result.get_jobject());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   151
    args.push_int(entry_bci);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   152
    args.push_long((jlong) (address) env);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   153
    args.push_int(env->task()->compile_id());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   154
    JavaCalls::call_special(&result, receiver->klass(),
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   155
                            vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   156
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   157
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   158
  // An uncaught exception was thrown during compilation.  Generally these
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   159
  // should be handled by the Java code in some useful way but if they leak
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   160
  // through to here report them instead of dying or silently ignoring them.
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   161
  if (HAS_PENDING_EXCEPTION) {
35143
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   162
    Handle exception(THREAD, PENDING_EXCEPTION);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   163
    CLEAR_PENDING_EXCEPTION;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   164
35557
029dcb9bfa8b 8146246: JVMCICompiler::abort_on_pending_exception: assert(!thread->owns_locks()) failed: must release all locks when leaving VM
twisti
parents: 35143
diff changeset
   165
    java_lang_Throwable::java_printStackTrace(exception, THREAD);
36612
2191de2a73f1 8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents: 35845
diff changeset
   166
    if (HAS_PENDING_EXCEPTION) {
2191de2a73f1 8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents: 35845
diff changeset
   167
      CLEAR_PENDING_EXCEPTION;
2191de2a73f1 8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents: 35845
diff changeset
   168
    }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   169
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   170
    env->set_failure("exception throw", false);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   171
  } else {
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   172
    oop result_object = (oop) result.get_jobject();
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   173
    if (result_object != NULL) {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   174
      oop failure_message = CompilationRequestResult::failureMessage(result_object);
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   175
      if (failure_message != NULL) {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   176
        const char* failure_reason = java_lang_String::as_utf8_string(failure_message);
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   177
        env->set_failure(failure_reason, CompilationRequestResult::retry(result_object) != 0);
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   178
      } else {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   179
        if (env->task()->code() == NULL) {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   180
          env->set_failure("no nmethod produced", true);
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   181
        } else {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   182
          env->task()->set_num_inlined_bytecodes(CompilationRequestResult::inlinedBytecodes(result_object));
35845
30025047885d 8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents: 35592
diff changeset
   183
          Atomic::inc(&_methods_compiled);
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   184
        }
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   185
      }
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   186
    } else {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   187
      assert(false, "JVMCICompiler.compileMethod should always return non-null");
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35557
diff changeset
   188
    }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   189
  }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   190
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
35143
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   192
/**
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   193
 * Aborts the VM due to an unexpected exception.
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   194
 */
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   195
void JVMCICompiler::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) {
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   196
  Thread* THREAD = Thread::current();
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   197
  CLEAR_PENDING_EXCEPTION;
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   198
35557
029dcb9bfa8b 8146246: JVMCICompiler::abort_on_pending_exception: assert(!thread->owns_locks()) failed: must release all locks when leaving VM
twisti
parents: 35143
diff changeset
   199
  java_lang_Throwable::java_printStackTrace(exception, THREAD);
35143
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   200
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   201
  // Give other aborting threads to also print their stack traces.
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   202
  // This can be very useful when debugging class initialization
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   203
  // failures.
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   204
  assert(THREAD->is_Java_thread(), "compiler threads should be Java threads");
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   205
  const bool interruptible = true;
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   206
  os::sleep(THREAD, 200, interruptible);
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   207
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   208
  vm_abort(dump_core);
33daaea9d5c2 8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents: 34185
diff changeset
   209
}
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   210
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   211
// Compilation entry point for methods
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents: 33160
diff changeset
   212
void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   213
  ShouldNotReachHere();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   214
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   215
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   216
bool JVMCICompiler::is_trivial(Method* method) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   217
  if (_bootstrapping) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   218
    return false;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   219
  }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   220
  return JVMCIRuntime::treat_as_trivial(method);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   221
}
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33451
diff changeset
   222
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   223
// Print compilation timers and statistics
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   224
void JVMCICompiler::print_timers() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   225
  print_compilation_timers();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   226
}
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   227
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   228
// Print compilation timers and statistics
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   229
void JVMCICompiler::print_compilation_timers() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   230
  TRACE_jvmci_1("JVMCICompiler::print_timers");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   231
  tty->print_cr("       JVMCI code install time:        %6.3f s",    _codeInstallTimer.seconds());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   232
}