1 /* 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #ifndef SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP 25 #define SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP 26 27 #include "interpreter/interpreter.hpp" 28 #include "memory/allocation.hpp" 29 #include "runtime/arguments.hpp" 30 #include "runtime/deoptimization.hpp" 31 32 class ParseClosure : public StackObj { 33 int _lineNo; 34 char* _filename; 35 bool _abort; 36 protected: 37 void abort() { _abort = true; } 38 void warn_and_abort(const char* message) { 39 warn(message); 40 abort(); 41 } 42 void warn(const char* message) { 43 warning("Error at line %d while parsing %s: %s", _lineNo, _filename == NULL ? "?" : _filename, message); 44 } 45 public: 46 ParseClosure() : _lineNo(0), _filename(NULL), _abort(false) {} 47 void parse_line(char* line) { 48 _lineNo++; 49 do_line(line); 50 } 51 virtual void do_line(char* line) = 0; 52 int lineNo() { return _lineNo; } 53 bool is_aborted() { return _abort; } 54 void set_filename(char* path) {_filename = path; _lineNo = 0;} 55 }; 56 57 #define CHECK_ABORT THREAD); \ 58 if (HAS_PENDING_EXCEPTION) { \ 59 char buf[256]; \ 60 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 61 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 62 return; \ 63 } \ 64 (void)(0 65 66 #define CHECK_ABORT_(result) THREAD); \ 67 if (HAS_PENDING_EXCEPTION) { \ 68 char buf[256]; \ 69 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 70 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 71 return result; \ 72 } \ 73 (void)(0 74 75 class JVMCIRuntime: public AllStatic { 76 private: 77 static jobject _HotSpotJVMCIRuntime_instance; 78 static bool _HotSpotJVMCIRuntime_initialized; 79 static const char* _compiler; 80 static const char* _options; 81 82 static bool _shutdown_called; 83 84 /** 85 * Instantiates a service object, calls its default constructor and returns it. 86 * 87 * @param name the name of a class implementing jdk.internal.jvmci.service.Service 88 */ 89 static Handle create_Service(const char* name, TRAPS); 90 91 public: 92 93 /** 94 * Parses *.properties files in jre/lib/jvmci/ and adds the properties to plist. 95 */ 96 static void parse_properties(SystemProperty** plist); 97 98 /** 99 * Saves the value of the "jvmci.compiler" system property for processing 100 * when JVMCI is initialized. 101 */ 102 static void save_compiler(const char* compiler); 103 104 /** 105 * Saves the value of the "jvmci.options" system property for processing 106 * when JVMCI is initialized. 107 */ 108 static void save_options(const char* options); 109 110 static void initialize_natives(JNIEnv *env, jclass c2vmClass); 111 112 static bool is_HotSpotJVMCIRuntime_initialized() { return _HotSpotJVMCIRuntime_initialized; } 113 114 /** 115 * Gets the singleton HotSpotJVMCIRuntime instance, initializing it if necessary 116 */ 117 static Handle get_HotSpotJVMCIRuntime(TRAPS) { 118 initialize_JVMCI(CHECK_(Handle())); 119 return Handle(JNIHandles::resolve_non_null(_HotSpotJVMCIRuntime_instance)); 120 } 121 122 static jobject get_HotSpotJVMCIRuntime_jobject(TRAPS) { 123 initialize_JVMCI(CHECK_NULL); 124 assert(_HotSpotJVMCIRuntime_initialized, "must be"); 125 return _HotSpotJVMCIRuntime_instance; 126 } 127 128 static Handle callStatic(const char* className, const char* methodName, const char* returnType, JavaCallArguments* args, TRAPS); 129 130 /** 131 * Trigger initialization of HotSpotJVMCIRuntime through JVMCI.getRuntime() 132 */ 133 static void initialize_JVMCI(TRAPS); 134 135 /** 136 * Explicitly initialize HotSpotJVMCIRuntime itself 137 */ 138 static void initialize_HotSpotJVMCIRuntime(TRAPS); 139 140 static void metadata_do(void f(Metadata*)); 141 142 static void shutdown(); 143 144 static bool shutdown_called() { 145 return _shutdown_called; 146 } 147 148 static void parse_lines(char* path, ParseClosure* closure, bool warnStatFailure); 149 150 /** 151 * Aborts the VM due to an unexpected exception. 152 */ 153 static void abort_on_pending_exception(Handle exception, const char* message, bool dump_core = false); 154 155 /** 156 * Calls Throwable.printStackTrace() on a given exception. 157 */ 158 static void call_printStackTrace(Handle exception, Thread* thread); 159 160 static BasicType kindToBasicType(jchar ch); 161 162 // The following routines are all called from compiled JVMCI code 163 164 static void new_instance(JavaThread* thread, Klass* klass); 165 static void new_array(JavaThread* thread, Klass* klass, jint length); 166 static void new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims); 167 static void dynamic_new_array(JavaThread* thread, oopDesc* element_mirror, jint length); 168 static void dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror); 169 static jboolean thread_is_interrupted(JavaThread* thread, oopDesc* obj, jboolean clear_interrupted); 170 static void vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3); 171 static jint identity_hash_code(JavaThread* thread, oopDesc* obj); 172 static address exception_handler_for_pc(JavaThread* thread); 173 static void monitorenter(JavaThread* thread, oopDesc* obj, BasicLock* lock); 174 static void monitorexit (JavaThread* thread, oopDesc* obj, BasicLock* lock); 175 static void create_null_exception(JavaThread* thread); 176 static void create_out_of_bounds_exception(JavaThread* thread, jint index); 177 static void vm_error(JavaThread* thread, jlong where, jlong format, jlong value); 178 static oopDesc* load_and_clear_exception(JavaThread* thread); 179 static void log_printf(JavaThread* thread, oopDesc* format, jlong v1, jlong v2, jlong v3); 180 static void log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline); 181 // Note: Must be kept in sync with constants in jdk.internal.jvmci.replacements.Log 182 enum { 183 LOG_OBJECT_NEWLINE = 0x01, 184 LOG_OBJECT_STRING = 0x02, 185 LOG_OBJECT_ADDRESS = 0x04 186 }; 187 static void log_object(JavaThread* thread, oopDesc* msg, jint flags); 188 static void write_barrier_pre(JavaThread* thread, oopDesc* obj); 189 static void write_barrier_post(JavaThread* thread, void* card); 190 static jboolean validate_object(JavaThread* thread, oopDesc* parent, oopDesc* child); 191 static void new_store_pre_barrier(JavaThread* thread); 192 193 // Test only function 194 static int test_deoptimize_call_int(JavaThread* thread, int value); 195 }; 196 197 // Tracing macros. 198 199 #define IF_TRACE_jvmci_1 if (!(JVMCITraceLevel >= 1)) ; else 200 #define IF_TRACE_jvmci_2 if (!(JVMCITraceLevel >= 2)) ; else 201 #define IF_TRACE_jvmci_3 if (!(JVMCITraceLevel >= 3)) ; else 202 #define IF_TRACE_jvmci_4 if (!(JVMCITraceLevel >= 4)) ; else 203 #define IF_TRACE_jvmci_5 if (!(JVMCITraceLevel >= 5)) ; else 204 205 #define TRACE_jvmci_1 if (!(JVMCITraceLevel >= 1 && (tty->print("JVMCITrace-1: "), true))) ; else tty->print_cr 206 #define TRACE_jvmci_2 if (!(JVMCITraceLevel >= 2 && (tty->print(" JVMCITrace-2: "), true))) ; else tty->print_cr 207 #define TRACE_jvmci_3 if (!(JVMCITraceLevel >= 3 && (tty->print(" JVMCITrace-3: "), true))) ; else tty->print_cr 208 #define TRACE_jvmci_4 if (!(JVMCITraceLevel >= 4 && (tty->print(" JVMCITrace-4: "), true))) ; else tty->print_cr 209 #define TRACE_jvmci_5 if (!(JVMCITraceLevel >= 5 && (tty->print(" JVMCITrace-5: "), true))) ; else tty->print_cr 210 211 #endif // SHARE_VM_JVMCI_JVMCI_RUNTIME_HPP