Index: vm/em/src/DrlEMImpl.cpp =================================================================== --- vm/em/src/DrlEMImpl.cpp (revision 632075) +++ vm/em/src/DrlEMImpl.cpp (working copy) @@ -26,7 +26,9 @@ #include "jit_import.h" #include "em_intf.h" +#include "component_manager.h" #include "open/vm.h" +#include "open/vm_adapter.h" #include "ini.h" #include "cxxlog.h" @@ -378,9 +380,21 @@ LECHO(2, "EM: Not a JIT shared lib: '{0}'" << libName.c_str()); return false; } - void (*_init)(JIT_Handle, const char*) = (void (*)(JIT_Handle, const char*)) fn; - _init(step.jit, step.jitName.c_str()); + OpenComponentManagerHandle p_cm = NULL; + int status = CmAcquire(&p_cm); + assert (status == JNI_OK) ; + OpenComponentHandle p_component = NULL; + status = p_cm->GetComponent(&p_component, "vmcore.vm"); + assert (status == JNI_OK) ; + OpenInterfaceHandle p_intf = NULL; + status = p_component->GetInterface(&p_intf, "open.interface.vmcore.vm.adapter"); + assert (status == JNI_OK) ; + OpenVmAdapterHandle p_vm_adapter = (OpenVmAdapterHandle)p_intf; + void (*_init)(JIT_Handle, const char*, vm_adaptor_t) = + (void (*)(JIT_Handle, const char*, vm_adaptor_t)) fn; + _init(step.jit, step.jitName.c_str(), p_vm_adapter->get_vm_interface); + bool pcEnabled = false; if (apr_dso_sym(&fn, libHandle, "JIT_set_profile_access_interface") == APR_SUCCESS) { pcEnabled = true; Index: vm/include/open/ee_em_intf.h =================================================================== --- vm/include/open/ee_em_intf.h (revision 632075) +++ vm/include/open/ee_em_intf.h (working copy) @@ -35,6 +35,8 @@ extern "C" { #endif +typedef void* (*vm_adaptor_t)(const char * name); + /** * Initializes JIT. * @@ -45,7 +47,7 @@ * @param[in] name - the persistent JIT name that the compiler uses to separate * its configuration settings from the ones of other JITs */ -JITEXPORT void JIT_init(JIT_Handle jit, const char* name); +JITEXPORT void JIT_init(JIT_Handle jit, const char* name, vm_adaptor_t adaptor); /** * De-initializes JIT. Index: vm/include/open/vm_interface.h =================================================================== --- vm/include/open/vm_interface.h (revision 0) +++ vm/include/open/vm_interface.h (revision 0) @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Intel, Pavel Afremov + * @version $Revision: 1.1 $ + */ +#ifndef _VM_INTERFACE_H +#define _VM_INTERFACE_H + +#include "jit_intf.h" + +#define PROTOTYPE_WITH_NAME(return_type, func_name, prototype) \ + typedef return_type (*func_name##_t)prototype;\ + const char* func_name##_s = #func_name + +#define GET_INTERFACE(get_adapter, func_name) \ + (func_name##_t)get_adapter(func_name##_s) + + +PROTOTYPE_WITH_NAME(void*, get_vm_interface, (const char* func_name)); + + +// Allocation Handle +PROTOTYPE_WITH_NAME(Class_Handle, allocation_handle_get_class, (Allocation_Handle ah)); + +//Class +PROTOTYPE_WITH_NAME(Class_Handle, class_get_array_of_class, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(Type_Info_Handle, class_get_element_type_info, (Class_Handle ch)); +PROTOTYPE_WITH_NAME(const char* , class_get_name, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(Class_Handle, class_get_super_class, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(Class_Handle, class_get_array_element_class, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(int , class_get_depth, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(VTable_Handle, class_get_vtable, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(Allocation_Handle, class_get_allocation_handle, (Class_Handle ch)); +PROTOTYPE_WITH_NAME(unsigned , class_get_boxed_data_size, (Class_Handle ch)); +PROTOTYPE_WITH_NAME(uint32 , class_get_num_array_dimensions, (Class_Handle cl, unsigned short cpIndex)); +PROTOTYPE_WITH_NAME(Class_Handle, class_get_class_of_primitive_type, (VM_Data_Type typ)); +PROTOTYPE_WITH_NAME(void* , class_get_const_string_intern_addr, (Class_Handle cl, unsigned index)); +PROTOTYPE_WITH_NAME(VM_Data_Type, class_get_const_type, (Class_Handle cl, unsigned index)); +PROTOTYPE_WITH_NAME(const void* , class_get_const_addr, (Class_Handle cl, unsigned index)); +PROTOTYPE_WITH_NAME(Method_Handle, class_get_method_by_name, (Class_Handle ch, const char* name)); +PROTOTYPE_WITH_NAME(Field_Handle, class_get_field_by_name, (Class_Handle ch, const char* name)); +PROTOTYPE_WITH_NAME(ClassLoaderHandle, class_get_class_loader, (Class_Handle ch)); + +PROTOTYPE_WITH_NAME(Boolean , class_is_array, (Class_Handle cl)); +PROTOTYPE_WITH_NAME(Boolean , class_is_enum, (Class_Handle ch)); +PROTOTYPE_WITH_NAME(Boolean , class_is_final, (Class_Handle cl)); //class_property_is_final +PROTOTYPE_WITH_NAME(Boolean , class_is_throwable, (Class_Handle ch)); //class_hint_is_exceptiontype +PROTOTYPE_WITH_NAME(Boolean , class_is_interface, (Class_Handle cl)); //class_property_is_interface2 +PROTOTYPE_WITH_NAME(Boolean , class_is_abstract, (Class_Handle cl)); //class_property_is_abstract +PROTOTYPE_WITH_NAME(Boolean , class_is_initialized, (Class_Handle ch)); //class_needs_initialization && class_is_initialized() +PROTOTYPE_WITH_NAME(Boolean , class_is_finalizable, (Class_Handle ch)); +PROTOTYPE_WITH_NAME(Boolean , class_is_instanceof, (Class_Handle s, Class_Handle t)); +PROTOTYPE_WITH_NAME(Boolean , class_is_support_fast_instanceof, (Class_Handle cl));// class_get_fast_instanceof_flag +PROTOTYPE_WITH_NAME(bool , class_is_primitive, (Class_Handle vmTypeHandle)); + +PROTOTYPE_WITH_NAME(Class_Handle, class_lookup_class_by_name_using_bootstrap_class_loader, (const char *name)); +PROTOTYPE_WITH_NAME(Method_Handle, class_lookup_method_recursively, + (Class_Handle clss, + const char *name, + const char *descr)); + +// Const Pool +PROTOTYPE_WITH_NAME(VM_Data_Type, class_cp_get_field_type, (Class_Handle src_class, unsigned short cp_index));// VM_Data_Type class_get_cp_field_type(Class_Handle src_class, unsigned short cp_index); +PROTOTYPE_WITH_NAME(const char* , class_cp_get_entry_signature, (Class_Handle src_class, unsigned short cp_index));//const char* class_get_cp_entry_signature(Class_Handle src_class, unsigned short index); ? const char* const_pool_get_field_descriptor(Class_Handle cl, unsigned index); +PROTOTYPE_WITH_NAME(bool , class_cp_is_entry_resolved, (Compile_Handle ch, Class_Handle clazz, unsigned short cp_index));//bool class_is_cp_entry_resolved(Compile_Handle ch, Class_Handle clazz, unsigned cp_index); +PROTOTYPE_WITH_NAME(const char* , class_cp_get_class_name, (Class_Handle cl, unsigned short cp_index));//const char* const_pool_get_class_name(Class_Handle cl, unsigned index); + +//Field + +PROTOTYPE_WITH_NAME(void* , field_get_address, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(Class_Handle, field_get_class, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(const char* , field_get_descriptor, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(const char* , field_get_name, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(unsigned , field_get_offset, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(Type_Info_Handle, field_get_type_info, (Field_Handle fh)); //field_get_type_info_of_field_value +PROTOTYPE_WITH_NAME(bool , field_is_final, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(bool , field_is_private, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(bool , field_is_static, (Field_Handle fh)); +PROTOTYPE_WITH_NAME(bool , field_is_volatile, (Field_Handle fh)); + +//Method + +PROTOTYPE_WITH_NAME(Method_Handle, method_get_overridden_method, (Class_Handle ch, Method_Handle mh));//method_find_overridden_method +PROTOTYPE_WITH_NAME(Byte* , method_get_info_block_jit, (Method_Handle m, JIT_Handle j)); +PROTOTYPE_WITH_NAME(unsigned , method_get_info_block_size_jit, (Method_Handle m, JIT_Handle j)); +PROTOTYPE_WITH_NAME(const char* , method_get_name, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(const char* , method_get_descriptor, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(const Byte* , method_get_byte_code_addr, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(uint32 , method_get_byte_code_size, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(uint16 , method_get_max_stack, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(uint32 , method_get_num_handlers, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(uint32 , method_get_offset, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(void* , method_get_indirect_address, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(uint32 , method_vars_get_number, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(unsigned , method_args_get_number, (Method_Signature_Handle mh)); +PROTOTYPE_WITH_NAME(Type_Info_Handle, method_args_get_type_info, (Method_Signature_Handle msh, unsigned idx)); +PROTOTYPE_WITH_NAME(Type_Info_Handle, method_ret_type_get_type_info, (Method_Signature_Handle msh)); +PROTOTYPE_WITH_NAME(Class_Handle, method_get_class, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(void , method_get_handler_info, + (Method_Handle mh, + unsigned handler_id, unsigned *begin_offset, + unsigned *end_offset, unsigned *handler_offset, + unsigned *handler_cpindex)); +PROTOTYPE_WITH_NAME(Byte* , method_get_code_block_addr_jit_new, + (Method_Handle mh, + JIT_Handle j, + int id)); +PROTOTYPE_WITH_NAME(unsigned , method_get_code_block_size_jit_new, + (Method_Handle nh, + JIT_Handle j, + int id)); +PROTOTYPE_WITH_NAME(Method_Side_Effects, method_get_side_effects, (Method_Handle mh)); + +PROTOTYPE_WITH_NAME(bool , method_has_annotation, (Method_Handle mh, Class_Handle antn_type)); +PROTOTYPE_WITH_NAME(bool , method_is_private, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_static, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_native, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_synchronized, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_final, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_abstract, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_strict, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_overridden, (Method_Handle mh)); +PROTOTYPE_WITH_NAME(bool , method_is_no_inlining, (Method_Handle mh)); + + +PROTOTYPE_WITH_NAME(void , method_set_side_effects, (Method_Handle mh, Method_Side_Effects mse)); +PROTOTYPE_WITH_NAME(void , method_set_num_target_handlers, + (Method_Handle mh, + JIT_Handle j, + unsigned num_handlers)); +PROTOTYPE_WITH_NAME(void , method_set_target_handler_info, + (Method_Handle mh, + JIT_Handle j, + unsigned eh_number, + void *start_ip, + void *end_ip, + void *handler_ip, + Class_Handle catch_cl, + bool exc_obj_is_dead)); + + +PROTOTYPE_WITH_NAME(void , method_lock, (Method_Handle m)); +PROTOTYPE_WITH_NAME(void , method_unlock, (Method_Handle m)); + +PROTOTYPE_WITH_NAME(Byte* , method_allocate_code_block, + (Method_Handle m, + JIT_Handle j, + size_t size, + size_t alignment, + CodeBlockHeat heat, + int id, + Code_Allocation_Action action)); +PROTOTYPE_WITH_NAME(Byte* , method_allocate_data_block, (Method_Handle m, JIT_Handle j, size_t size, size_t alignment)); +PROTOTYPE_WITH_NAME(Byte* , method_allocate_info_block, (Method_Handle m, JIT_Handle j, size_t size)); +PROTOTYPE_WITH_NAME(Byte* , method_allocate_jit_data_block, (Method_Handle m, JIT_Handle j, size_t size, size_t alignment)); + + +//Object +PROTOTYPE_WITH_NAME(int , object_get_vtable_offset, ()); + + +//Resolve +PROTOTYPE_WITH_NAME(Class_Handle, resolve_class, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Class_Handle, resolve_class_new, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Method_Handle, resolve_special_method, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Method_Handle, resolve_interface_method, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Method_Handle, resolve_static_method, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Method_Handle, resolve_virtual_method, (Compile_Handle h, Class_Handle c, unsigned index)); +PROTOTYPE_WITH_NAME(Field_Handle, resolve_nonstatic_field, + (Compile_Handle h, + Class_Handle c, + unsigned index, + unsigned putfield)); +PROTOTYPE_WITH_NAME(Field_Handle, resolve_static_field, + (Compile_Handle h, + Class_Handle c, + unsigned index, + unsigned putfield)); + +//Type Info + +PROTOTYPE_WITH_NAME(Type_Info_Handle, type_info_create_from_java_descriptor, (ClassLoaderHandle cl, const char* typeName)); + +PROTOTYPE_WITH_NAME(const char* , type_info_get_type_name, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(Class_Handle, type_info_get_class, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(Class_Handle, type_info_get_class_no_exn, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(uint32 , type_info_get_num_array_dimensions, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(Type_Info_Handle, type_info_get_type_info, (Type_Info_Handle tih)); + +PROTOTYPE_WITH_NAME(bool , type_info_is_void, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(bool , type_info_is_reference, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(bool , type_info_is_resolved, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(bool , type_info_is_primitive, (Type_Info_Handle tih)); +PROTOTYPE_WITH_NAME(bool , type_info_is_vector, (Type_Info_Handle tih)); + +//Vector +PROTOTYPE_WITH_NAME(int , vector_get_first_element_offset, (Class_Handle element_type)); //vector_first_element_offset_class_handle +PROTOTYPE_WITH_NAME(int , vector_get_length_offset, ()); //vector_length_offset + +//Vm +PROTOTYPE_WITH_NAME(int , vm_tls_alloc, (int* key)); //IDATA VMCALL hythread_tls_alloc(hythread_tls_key_t *handle) +PROTOTYPE_WITH_NAME(int , vm_tls_get_offset, (int key)); //UDATA VMCALL hythread_tls_get_offset(hythread_tls_key_t key) +PROTOTYPE_WITH_NAME(int , vm_tls_get_request_offset, ()); //DATA VMCALL hythread_tls_get_request_offset +PROTOTYPE_WITH_NAME(unsigned , vm_tls_is_fast, (void));//UDATA VMCALL hythread_uses_fast_tls +PROTOTYPE_WITH_NAME(int , vm_get_tls_offset_in_segment, (void));//IDATA VMCALL hythread_get_hythread_offset_in_tls(void) + +PROTOTYPE_WITH_NAME(Class_Handle, vm_get_system_object_class, ()); // get_system_object_class +PROTOTYPE_WITH_NAME(Class_Handle, vm_get_system_class_class, ()); // get_system_class_class +PROTOTYPE_WITH_NAME(Class_Handle, vm_get_system_string_class, ()); // get_system_string_class +PROTOTYPE_WITH_NAME(void* , vm_get_vtable_base, ()); //POINTER_SIZE_INT vm_get_vtable_base() +PROTOTYPE_WITH_NAME(void* , vm_get_heap_base_address, ()); //vm_heap_base_address +PROTOTYPE_WITH_NAME(void* , vm_get_heap_ceiling_address, ()); //vm_heap_ceiling_address +PROTOTYPE_WITH_NAME(Boolean , vm_is_heap_compressed, ());//vm_references_are_compressed(); +PROTOTYPE_WITH_NAME(Boolean , vm_is_vtable_compressed, ());//vm_vtable_pointers_are_compressed(); +PROTOTYPE_WITH_NAME(void , vm_patch_code_block, (Byte *code_block, Byte *new_code, size_t size)); +PROTOTYPE_WITH_NAME(JIT_Result , vm_compile_method, (JIT_Handle jit, Method_Handle method)); +PROTOTYPE_WITH_NAME(void , vm_register_jit_extended_class_callback, + (JIT_Handle jit, + Class_Handle clss, + void* callback_data)); +PROTOTYPE_WITH_NAME(void , vm_register_jit_overridden_method_callback, + (JIT_Handle jit, + Method_Handle method, + void* callback_data)); +PROTOTYPE_WITH_NAME(void , vm_register_jit_recompiled_method_callback, + (JIT_Handle jit, + Method_Handle method, + void *callback_data)); +PROTOTYPE_WITH_NAME(void , vm_compiled_method_load, + (Method_Handle method, uint32 codeSize, + void* codeAddr, + uint32 mapLength, + AddrLocation* addrLocationMap, + void* compileInfo, + Method_Handle outer_method));//compiled_method_load + +//VTable +PROTOTYPE_WITH_NAME(Class_Handle , vtable_get_class, (VTable_Handle vh)); + + +#endif // _VM_INTERFACE_H Property changes on: vm/include/open/vm_interface.h ___________________________________________________________________ Name: svn:executable + * Index: vm/include/open/vm_adapter.h =================================================================== --- vm/include/open/vm_adapter.h (revision 0) +++ vm/include/open/vm_adapter.h (revision 0) @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Intel, Pavel Afremov + * @version $Revision: 1.1 $ + */ +#ifndef _VM_ADAPTER_H +#define _VM_ADAPTER_H + +struct _OpenVmAdapter { + void* (*get_vm_interface)(const char* func_name); +}; +typedef const struct _OpenVmAdapter* OpenVmAdapterHandle; + +#endif // _VM_ADAPTER_H Property changes on: vm/include/open/vm_adapter.h ___________________________________________________________________ Name: svn:executable + * Index: vm/vmcore/build/vmcore.exp =================================================================== --- vm/vmcore/build/vmcore.exp (revision 632075) +++ vm/vmcore/build/vmcore.exp (working copy) @@ -142,6 +142,7 @@ get_system_object_class; get_system_string_class; get_thread_ptr; + get_vm_interface; initialize_arg_list_iterator; init_log_system; is_enabled; @@ -602,6 +603,7 @@ vector_get_length; vector_length_offset; verify_object_header; + vm_adapter_initialize; vm_attach; vm_check_if_monitor; vm_compile_method; Index: vm/vmcore/src/init/vm_init.cpp =================================================================== --- vm/vmcore/src/init/vm_init.cpp (revision 632075) +++ vm/vmcore/src/init/vm_init.cpp (working copy) @@ -27,6 +27,8 @@ #include "open/gc.h" #include "open/hythread_ext.h" #include "open/jthread.h" // this is for jthread_self() +#include "open/vm_adapter.h" +#include "open/vm_interface.h" #include "init.h" #include "classloader.h" @@ -120,7 +122,198 @@ } } //create_instance_for_class +// VM adapter part +static apr_dso_handle_t* get_harmonyvm_handle(){ + apr_dso_handle_t* descriptor; + apr_pool_t* pool; + int ret = apr_pool_create(&pool, NULL); + assert(APR_SUCCESS == ret); + ret = apr_dso_load(&descriptor, PORT_DSO_NAME("harmonyvm"), pool); + assert(APR_SUCCESS == ret); + return descriptor; +} + +VMEXPORT +void* get_vm_interface(const char* func_name){ + static apr_dso_handle_t* descriptor = get_harmonyvm_handle(); + void* p_func = NULL; + int ret = apr_dso_sym((apr_dso_handle_sym_t*) &p_func, descriptor, func_name); + + //assert(APR_SUCCESS == ret); + + //FIXME: temporary solution, should be fixed in next patch + if (p_func) { + return p_func; + } else if (strcmp(func_name,"class_is_final") == 0) { + return (void*)class_property_is_final; + } else if (strcmp(func_name,"class_is_throwable") == 0) { + return (void*)class_hint_is_exceptiontype; + } else if (strcmp(func_name,"class_is_interface") == 0) { + return (void*)class_property_is_interface2; + } else if (strcmp(func_name,"class_is_abstract") == 0) { + return (void*)class_property_is_abstract; + } else if (strcmp(func_name,"class_cp_get_field_type") == 0) { + return (void*)class_get_cp_field_type; + } else if (strcmp(func_name,"class_cp_get_entry_signature") == 0) { + return (void*)class_get_cp_entry_signature; + } else if (strcmp(func_name,"class_cp_is_entry_resolved") == 0) { + return (void*)class_is_cp_entry_resolved; + } else if (strcmp(func_name,"class_cp_get_class_name") == 0) { + return (void*)const_pool_get_class_name; + } else if (strcmp(func_name,"field_get_type_info") == 0) { + return (void*)field_get_type_info_of_field_value; + } else if (strcmp(func_name,"method_get_overridden_method") == 0) { + return (void*)method_find_overridden_method; + } else if (strcmp(func_name,"vector_get_first_element_offset") == 0) { + return (void*)vector_first_element_offset_class_handle; + } else if (strcmp(func_name,"vector_get_length_offset") == 0) { + return (void*)vector_length_offset; + } else if (strcmp(func_name,"vm_tls_alloc") == 0) { + return (void*)hythread_tls_alloc; + } else if (strcmp(func_name,"vm_tls_get_offset") == 0) { + return (void*)hythread_tls_get_offset; + } else if (strcmp(func_name,"vm_tls_get_request_offset") == 0) { + return (void*)hythread_tls_get_request_offset; + } else if (strcmp(func_name,"vm_tls_is_fast") == 0) { + return (void*)hythread_uses_fast_tls; + } else if (strcmp(func_name,"vm_get_tls_offset_in_segment") == 0) { + return (void*)hythread_get_hythread_offset_in_tls; + } else if (strcmp(func_name,"vm_get_system_object_class") == 0) { + return (void*)get_system_object_class; + } else if (strcmp(func_name,"vm_get_system_class_class") == 0) { + return (void*)get_system_class_class; + } else if (strcmp(func_name,"vm_get_system_string_class") == 0) { + return (void*)get_system_string_class; + } else if (strcmp(func_name,"vm_get_heap_base_address") == 0) { + return (void*)vm_heap_base_address; + } else if (strcmp(func_name,"vm_get_heap_ceiling_address") == 0) { + return (void*)vm_heap_ceiling_address; + } else if (strcmp(func_name,"vm_is_heap_compressed") == 0) { + return (void*)vm_references_are_compressed; + } else if (strcmp(func_name,"vm_is_vtable_compressed") == 0) { + return (void*)vm_vtable_pointers_are_compressed; + } else if (strcmp(func_name,"vm_compiled_method_load") == 0) { + return (void*)compiled_method_load; + } else { + return NULL; + } +} + +// VM adapter open interface part +static OpenComponentHandle open_adapter_component_interface = NULL; +static OpenInstanceAllocatorHandle open_adapter_allocator_interface = NULL; +static OpenVmAdapterHandle open_adapter_vmcore_adapter = NULL; +static apr_pool_t* open_adapter_vm_pool = NULL; + +static const char* +open_adapter_get_name() { + return "vmcore.vm"; +} + +static const char* +open_adapter_get_version() { + return "1.0"; +} + +static const char* +open_adapter_get_description() { + return "VM Core ..."; +} + +static const char* +open_adapter_get_vendor() { + return "Intel"; +} + +static const char* +open_adapter_get_property(const char* key) { + return NULL; +} + +static const char* open_adapter_interface_names[] = { + "open.interface.vmcore.vm.adapter", + NULL +}; + +static const char** +open_adapter_list_interface_names() { + return open_adapter_interface_names; +} + +static int +open_adapter_get_interface(OpenInterfaceHandle* p_intf, + const char* intf_name) { + if (!strcmp(intf_name, open_adapter_interface_names[0])) { + *p_intf = (OpenInterfaceHandle) open_adapter_vmcore_adapter; + return JNI_OK; + } else { + return JNI_ERR; + } +} + +static int +open_adapter_free() { + return JNI_OK; +} + +static int +open_adapter_create_instance(OpenInstanceHandle* p_instance, + apr_pool_t* pool) { + struct _OpenInstance* instance = (struct _OpenInstance*) apr_palloc(pool, sizeof(_OpenComponent)); + + instance->intf = open_adapter_component_interface; + *p_instance = instance; + return JNI_OK; +} + +static int +open_adapter_free_instance(OpenInstanceHandle instance) { + return JNI_OK; +} + +VMEXPORT +int vm_adapter_initialize(OpenComponentHandle* p_component, + OpenInstanceAllocatorHandle* p_allocator, + apr_pool_t* pool) +{ + if (open_adapter_component_interface + || open_adapter_allocator_interface + || open_adapter_vmcore_adapter) { + /* Virtual table already initialized */ + return JNI_ERR; + } + open_adapter_vm_pool = pool; + + struct _OpenComponent* c_intf = (struct _OpenComponent*) apr_palloc(pool, sizeof(_OpenComponent)); + + c_intf->GetName = open_adapter_get_name; + c_intf->GetVersion = open_adapter_get_version; + c_intf->GetDescription = open_adapter_get_description; + c_intf->GetVendor = open_adapter_get_vendor; + c_intf->GetProperty = open_adapter_get_property; + c_intf->ListInterfaceNames = open_adapter_list_interface_names; + c_intf->GetInterface = open_adapter_get_interface; + c_intf->Free = open_adapter_free; + + _OpenInstanceAllocator* a_intf = (_OpenInstanceAllocator*) + apr_palloc(pool, sizeof(_OpenInstanceAllocator)); + a_intf->CreateInstance = open_adapter_create_instance; + a_intf->FreeInstance = open_adapter_free_instance; + + _OpenVmAdapter* adapter = (_OpenVmAdapter*) apr_palloc(pool, sizeof(_OpenVmAdapter)); + adapter->get_vm_interface = get_vm_interface; + + open_adapter_component_interface = (OpenComponentHandle) c_intf; + open_adapter_allocator_interface = (OpenInstanceAllocatorHandle) a_intf; + open_adapter_vmcore_adapter = (OpenVmAdapterHandle) adapter; + + *p_component = open_adapter_component_interface; + *p_allocator = open_adapter_allocator_interface; + return JNI_OK; +} + + #define GC_DLL_COMP PORT_DSO_NAME("gc_gen") #define GC_DLL_UNCOMP PORT_DSO_NAME("gc_gen_uncomp") @@ -138,7 +331,15 @@ */ static jint process_properties_dlls(Global_Env * vm_env) { jint status; + OpenInstanceHandle vm_adapter_instance; + status = CmAddComponent(vm_adapter_initialize); + assert (status == JNI_OK) ; + status = vm_env->cm->CreateInstance(&(vm_adapter_instance), "vmcore.vm"); + assert (status == JNI_OK) ; + vm_get_heap_ceiling_address_t func = GET_INTERFACE(get_vm_interface, vm_get_heap_ceiling_address); + printf("\n\tfunc = %p\n", func); + if (!vm_env->VmProperties()->is_set("vm.em_dll")) { vm_env->VmProperties()->set("vm.em_dll", PORT_DSO_NAME("em")); } @@ -151,7 +352,7 @@ LWARN(13, "Cannot load EM component from {0}" << dll); return status; } - + status = vm_env->cm->CreateInstance(&(vm_env->em_instance), "em"); if (status != JNI_OK) { LWARN(14, "Cannot instantiate EM"); Index: vm/jitrino/src/vm/JITInterface.cpp =================================================================== --- vm/jitrino/src/vm/JITInterface.cpp (revision 632075) +++ vm/jitrino/src/vm/JITInterface.cpp (working copy) @@ -38,6 +38,7 @@ #include "jit_export.h" #include "jit_export_jpda.h" #include "open/types.h" +#include "open/vm_interface.h" #define LOG_DOMAIN "jitrino" #include "cxxlog.h" @@ -76,8 +77,11 @@ // Called once at the end of the constructor. extern "C" JITEXPORT void -JIT_init(JIT_Handle jit, const char* name) +JIT_init(JIT_Handle jit, const char* name, vm_adaptor_t adaptor) { + vm_get_heap_ceiling_address_t func = GET_INTERFACE(adaptor, vm_get_heap_ceiling_address); + printf("\n\tfunc = %p\n", func); + std::string initMessage = std::string("Initializing Jitrino.") + name + " -> "; std::string mode = "OPT";