1 /* 2 * Copyright (c) 1999, 2013, 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 25 #ifndef SHARE_VM_CI_CIUTILITIES_HPP 26 #define SHARE_VM_CI_CIUTILITIES_HPP 27 28 #include "ci/ciEnv.hpp" 29 #include "runtime/interfaceSupport.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 32 // The following routines and definitions are used internally in the 33 // compiler interface. 34 35 36 // Add a ci native entry wrapper? 37 38 // Bring the compilation thread into the VM state. 39 #define VM_ENTRY_MARK \ 40 CompilerThread* thread=CompilerThread::current(); \ 41 ThreadInVMfromNative __tiv(thread); \ 42 ResetNoHandleMark rnhm; \ 43 HandleMarkCleaner __hm(thread); \ 44 Thread* THREAD = thread; \ 45 debug_only(VMNativeEntryWrapper __vew;) 46 47 48 49 // Bring the compilation thread into the VM state. No handle mark. 50 #define VM_QUICK_ENTRY_MARK \ 51 CompilerThread* thread=CompilerThread::current(); \ 52 ThreadInVMfromNative __tiv(thread); \ 53 /* \ 54 * [TODO] The NoHandleMark line does nothing but declare a function prototype \ 55 * The NoHandkeMark constructor is NOT executed. If the ()'s are \ 56 * removed, causes the NoHandleMark assert to trigger. \ 57 * debug_only(NoHandleMark __hm();) \ 58 */ \ 59 Thread* THREAD = thread; \ 60 debug_only(VMNativeEntryWrapper __vew;) 61 62 63 #define EXCEPTION_CONTEXT \ 64 CompilerThread* thread=CompilerThread::current(); \ 65 Thread* THREAD = thread; 66 67 68 #define CURRENT_ENV \ 69 ciEnv::current() 70 71 // where current thread is THREAD 72 #define CURRENT_THREAD_ENV \ 73 ciEnv::current(thread) 74 75 #define IS_IN_VM \ 76 ciEnv::is_in_vm() 77 78 #define ASSERT_IN_VM \ 79 assert(IS_IN_VM, "must be in vm state"); 80 81 #define GUARDED_VM_ENTRY(action) \ 82 {if (IS_IN_VM) { action } else { VM_ENTRY_MARK; { action }}} 83 84 #define GUARDED_VM_QUICK_ENTRY(action) \ 85 {if (IS_IN_VM) { action } else { VM_QUICK_ENTRY_MARK; { action }}} 86 87 // Redefine this later. 88 #define KILL_COMPILE_ON_FATAL_(result) \ 89 THREAD); \ 90 if (HAS_PENDING_EXCEPTION) { \ 91 if (PENDING_EXCEPTION->klass() == \ 92 SystemDictionary::ThreadDeath_klass()) { \ 93 /* Kill the compilation. */ \ 94 fatal("unhandled ci exception"); \ 95 return (result); \ 96 } \ 97 CLEAR_PENDING_EXCEPTION; \ 98 return (result); \ 99 } \ 100 (void)(0 101 102 #define KILL_COMPILE_ON_ANY \ 103 THREAD); \ 104 if (HAS_PENDING_EXCEPTION) { \ 105 fatal("unhandled ci exception"); \ 106 CLEAR_PENDING_EXCEPTION; \ 107 } \ 108 (void)(0 109 110 111 inline const char* bool_to_str(bool b) { 112 return ((b) ? "true" : "false"); 113 } 114 115 const char* basictype_to_str(BasicType t); 116 const char basictype_to_char(BasicType t); 117 118 jbyte *ci_card_table_address(); 119 template <typename T> T ci_card_table_address_as() { 120 return reinterpret_cast<T>(ci_card_table_address()); 121 } 122 123 #endif // SHARE_VM_CI_CIUTILITIES_HPP