jvmciCompilerToVM.hpp revision 9287:40bd4478a362
1/* 2 * Copyright (c) 2011, 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#ifndef SHARE_VM_JVMCI_JVMCI_COMPILER_TO_VM_HPP 25#define SHARE_VM_JVMCI_JVMCI_COMPILER_TO_VM_HPP 26 27#include "prims/jni.h" 28#include "runtime/javaCalls.hpp" 29#include "jvmci/jvmciJavaClasses.hpp" 30 31class CompilerToVM { 32public: 33 /** 34 * Tag bits used by lookupKlassInPool to distinguish the types in Java. 35 */ 36 enum Tags { 37 KLASS_TAG = 0x0, 38 SYMBOL_TAG = 0x1 39 }; 40 41 // FIXME This is only temporary until the GC code is changed. 42 static bool _supports_inline_contig_alloc; 43 static HeapWord** _heap_end_addr; 44 static HeapWord** _heap_top_addr; 45 46 static intptr_t tag_pointer(Klass* klass) { 47 return ((intptr_t) klass) | KLASS_TAG; 48 } 49 50 static intptr_t tag_pointer(Symbol* symbol) { 51 return ((intptr_t) symbol) | SYMBOL_TAG; 52 } 53 54 static JNINativeMethod methods[]; 55 static int methods_count(); 56 57 static inline Method* asMethod(jobject jvmci_method) { 58 return (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(jvmci_method); 59 } 60 61 static inline Method* asMethod(Handle jvmci_method) { 62 return (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(jvmci_method); 63 } 64 65 static inline Method* asMethod(oop jvmci_method) { 66 return (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(jvmci_method); 67 } 68 69 static inline ConstantPool* asConstantPool(jobject jvmci_constant_pool) { 70 return (ConstantPool*) (address) HotSpotConstantPool::metaspaceConstantPool(jvmci_constant_pool); 71 } 72 73 static inline ConstantPool* asConstantPool(Handle jvmci_constant_pool) { 74 return (ConstantPool*) (address) HotSpotConstantPool::metaspaceConstantPool(jvmci_constant_pool); 75 } 76 77 static inline ConstantPool* asConstantPool(oop jvmci_constant_pool) { 78 return (ConstantPool*) (address) HotSpotConstantPool::metaspaceConstantPool(jvmci_constant_pool); 79 } 80 81 static inline Klass* asKlass(jobject jvmci_type) { 82 return java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(jvmci_type)); 83 } 84 85 static inline Klass* asKlass(Handle jvmci_type) { 86 return java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(jvmci_type)); 87 } 88 89 static inline Klass* asKlass(oop jvmci_type) { 90 return java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(jvmci_type)); 91 } 92 93 static inline MethodData* asMethodData(jlong metaspaceMethodData) { 94 return (MethodData*) (address) metaspaceMethodData; 95 } 96 97 static oop get_jvmci_method(methodHandle method, TRAPS); 98 99 static oop get_jvmci_type(KlassHandle klass, TRAPS); 100 101 static void invalidate_installed_code(Handle installedCode, TRAPS); 102}; 103 104class JavaArgumentUnboxer : public SignatureIterator { 105 protected: 106 JavaCallArguments* _jca; 107 arrayOop _args; 108 int _index; 109 110 oop next_arg(BasicType expectedType) { 111 assert(_index < _args->length(), "out of bounds"); 112 oop arg=((objArrayOop) (_args))->obj_at(_index++); 113 assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch"); 114 return arg; 115 } 116 117 public: 118 JavaArgumentUnboxer(Symbol* signature, JavaCallArguments* jca, arrayOop args, bool is_static) : SignatureIterator(signature) { 119 this->_return_type = T_ILLEGAL; 120 _jca = jca; 121 _index = 0; 122 _args = args; 123 if (!is_static) { 124 _jca->push_oop(next_arg(T_OBJECT)); 125 } 126 iterate(); 127 assert(_index == args->length(), "arg count mismatch with signature"); 128 } 129 130 inline void do_bool() { if (!is_return_type()) _jca->push_int(next_arg(T_BOOLEAN)->bool_field(java_lang_boxing_object::value_offset_in_bytes(T_BOOLEAN))); } 131 inline void do_char() { if (!is_return_type()) _jca->push_int(next_arg(T_CHAR)->char_field(java_lang_boxing_object::value_offset_in_bytes(T_CHAR))); } 132 inline void do_short() { if (!is_return_type()) _jca->push_int(next_arg(T_SHORT)->short_field(java_lang_boxing_object::value_offset_in_bytes(T_SHORT))); } 133 inline void do_byte() { if (!is_return_type()) _jca->push_int(next_arg(T_BYTE)->byte_field(java_lang_boxing_object::value_offset_in_bytes(T_BYTE))); } 134 inline void do_int() { if (!is_return_type()) _jca->push_int(next_arg(T_INT)->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT))); } 135 136 inline void do_long() { if (!is_return_type()) _jca->push_long(next_arg(T_LONG)->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG))); } 137 inline void do_float() { if (!is_return_type()) _jca->push_float(next_arg(T_FLOAT)->float_field(java_lang_boxing_object::value_offset_in_bytes(T_FLOAT))); } 138 inline void do_double() { if (!is_return_type()) _jca->push_double(next_arg(T_DOUBLE)->double_field(java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE))); } 139 140 inline void do_object() { _jca->push_oop(next_arg(T_OBJECT)); } 141 inline void do_object(int begin, int end) { if (!is_return_type()) _jca->push_oop(next_arg(T_OBJECT)); } 142 inline void do_array(int begin, int end) { if (!is_return_type()) _jca->push_oop(next_arg(T_OBJECT)); } 143 inline void do_void() { } 144}; 145 146#endif // SHARE_VM_JVMCI_JVMCI_COMPILER_TO_VM_HPP 147