LCOV - code coverage report
Current view: top level - native/vm - nativevm.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 30 30 100.0 %
Date: 2017-07-14 10:03:36 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* src/native/vm/nativevm.cpp - Register native VM interface functions.
       2             : 
       3             :    Copyright (C) 1996-2013
       4             :    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
       5             : 
       6             :    This file is part of CACAO.
       7             : 
       8             :    This program is free software; you can redistribute it and/or
       9             :    modify it under the terms of the GNU General Public License as
      10             :    published by the Free Software Foundation; either version 2, or (at
      11             :    your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful, but
      14             :    WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16             :    General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program; if not, write to the Free Software
      20             :    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
      21             :    02110-1301, USA.
      22             : 
      23             : */
      24             : 
      25             : 
      26             : #include "config.h"
      27             : 
      28             : #include "native/vm/nativevm.hpp"
      29             : 
      30             : #include "toolbox/logging.hpp"
      31             : 
      32             : #include "vm/class.hpp"
      33             : #include "vm/exceptions.hpp"
      34             : #include "vm/initialize.hpp"
      35             : #include "vm/options.hpp"
      36             : #include "vm/os.hpp"
      37             : #include "vm/jit/builtin.hpp"
      38             : 
      39             : #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
      40             : # include "native/native.hpp"
      41             : 
      42             : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
      43             : # include "native/vm/openjdk/hpi.hpp"
      44             : #endif
      45             : 
      46             : # include "toolbox/buffer.hpp"
      47             : 
      48             : # include "vm/globals.hpp"
      49             : # include "vm/properties.hpp"
      50             : # include "vm/utf8.hpp"
      51             : # include "vm/vm.hpp"
      52             : #endif
      53             : 
      54             : 
      55             : /* nativevm_preinit ************************************************************
      56             : 
      57             :    Pre-initialize the implementation specific native stuff.
      58             : 
      59             : *******************************************************************************/
      60             : 
      61         163 : void nativevm_preinit(void)
      62             : {
      63         163 :         TRACESUBSYSTEMINITIALIZATION("nativevm_preinit");
      64             : 
      65             :         /* Register native methods of all classes implemented. */
      66             : 
      67             : #if defined(ENABLE_JAVASE)
      68             : # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
      69             : 
      70         163 :         _Jv_gnu_classpath_VMStackWalker_init();
      71         163 :         _Jv_gnu_classpath_VMSystemProperties_init();
      72         163 :         _Jv_gnu_java_lang_VMCPStringBuilder_init();
      73         163 :         _Jv_gnu_java_lang_management_VMClassLoadingMXBeanImpl_init();
      74         163 :         _Jv_gnu_java_lang_management_VMMemoryMXBeanImpl_init();
      75         163 :         _Jv_gnu_java_lang_management_VMRuntimeMXBeanImpl_init();
      76         163 :         _Jv_gnu_java_lang_management_VMThreadMXBeanImpl_init();
      77         163 :         _Jv_java_lang_VMClass_init();
      78         163 :         _Jv_java_lang_VMClassLoader_init();
      79         163 :         _Jv_java_lang_VMObject_init();
      80         163 :         _Jv_java_lang_VMRuntime_init();
      81         163 :         _Jv_java_lang_VMSystem_init();
      82         163 :         _Jv_java_lang_VMString_init();
      83         163 :         _Jv_java_lang_VMThread_init();
      84         163 :         _Jv_java_lang_VMThrowable_init();
      85         163 :         _Jv_java_lang_management_VMManagementFactory_init();
      86         163 :         _Jv_java_lang_reflect_VMConstructor_init();
      87         163 :         _Jv_java_lang_reflect_VMField_init();
      88         163 :         _Jv_java_lang_reflect_VMMethod_init();
      89             :         //_Jv_java_lang_reflect_VMProxy_init();
      90         163 :         _Jv_java_security_VMAccessController_init();
      91         163 :         _Jv_java_util_concurrent_atomic_AtomicLong_init();
      92         163 :         _Jv_sun_misc_Unsafe_init();
      93             : 
      94             : #if defined(ENABLE_ANNOTATIONS)
      95         163 :         _Jv_sun_reflect_ConstantPool_init();
      96             : #endif
      97             : 
      98             : #if defined(ENABLE_COMPILER2)
      99         163 :         _Jv_org_cacaojvm_compiler2_test_Compiler2Test_init();
     100             : #endif
     101             : 
     102             : # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
     103             : 
     104             :         // Load libjava.so
     105             :         VM* vm = VM::get_current();
     106             :         Properties& properties = vm->get_properties();
     107             :         const char* boot_library_path = properties.get("sun.boot.library.path");
     108             : 
     109             :         // Use Buffer to assemble library path.
     110             :         Buffer<> buf;
     111             : 
     112             :         buf.write(boot_library_path);
     113             :         buf.write("/libjava.so");
     114             : 
     115             :         Utf8String u = buf.utf8_str();
     116             : 
     117             :         NativeLibrary nl(u);
     118             :         void* handle = nl.open();
     119             : 
     120             :         if (handle == NULL)
     121             :                 os::abort("nativevm_init: failed to open libjava.so at: %s", buf.c_str());
     122             : 
     123             :         NativeLibraries& nls = vm->get_nativelibraries();
     124             :         nls.add(nl);
     125             : 
     126             : #ifndef WITH_JAVA_RUNTIME_LIBRARY_OPENJDK_7
     127             :         // Initialize the HPI.
     128             :         HPI& hpi = vm->get_hpi();
     129             :         hpi.initialize();
     130             : #endif
     131             : 
     132             :         _Jv_sun_misc_Perf_init();
     133             :         _Jv_sun_misc_Unsafe_init();
     134             : 
     135             : #  if !defined(NDEBUG)
     136             :         // Sanity check current time in milliseconds, because negative values
     137             :         // might confuse OpenJDKs sanity checks.
     138             :         if (opt_PrintWarnings && (builtin_currenttimemillis() < 0))
     139             :                 log_println("nativevm_preinit: Current time in milliseconds is negative, please check your time!");
     140             : #  endif
     141             : 
     142             : # else
     143             : #  error unknown classpath configuration
     144             : # endif
     145             : 
     146             : #elif defined(ENABLE_JAVAME_CLDC1_1)
     147             : 
     148             :         _Jv_com_sun_cldc_io_ResourceInputStream_init();
     149             :         _Jv_com_sun_cldc_io_j2me_socket_Protocol_init();
     150             :         _Jv_com_sun_cldchi_io_ConsoleOutputStream_init();
     151             :         _Jv_com_sun_cldchi_jvm_JVM_init();
     152             :         _Jv_java_lang_Class_init();
     153             :         _Jv_java_lang_Double_init();
     154             :         _Jv_java_lang_Float_init();
     155             :         _Jv_java_lang_Math_init();
     156             :         _Jv_java_lang_Object_init();
     157             :         _Jv_java_lang_Runtime_init();
     158             :         _Jv_java_lang_String_init();
     159             :         _Jv_java_lang_System_init();
     160             :         _Jv_java_lang_Thread_init();
     161             :         _Jv_java_lang_Throwable_init();
     162             : 
     163             : #else
     164             : # error unknown Java configuration
     165             : #endif
     166         163 : }
     167             : 
     168             : 
     169             : /* nativevm_init ***************************************************************
     170             : 
     171             :    Initialize the implementation specific native stuff.
     172             : 
     173             : *******************************************************************************/
     174             : 
     175         163 : bool nativevm_init(void)
     176             : {
     177         163 :         TRACESUBSYSTEMINITIALIZATION("nativevm_init");
     178             : 
     179             : #if defined(ENABLE_JAVASE)
     180             : 
     181             : # if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
     182             : 
     183             :         // Nothing to do.
     184             : 
     185             : # elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
     186             : 
     187             :         methodinfo* m = class_resolveclassmethod(class_java_lang_System,
     188             :                                                  Utf8String::from_utf8("initializeSystemClass"),
     189             :                                                  utf8::void__void,
     190             :                                                  class_java_lang_Object,
     191             :                                                  false);
     192             : 
     193             :         if (m == NULL)
     194             :                 return false;
     195             : 
     196             :         (void) vm_call_method(m, NULL);
     197             : 
     198             :         if (exceptions_get_exception() != NULL)
     199             :                 return false;
     200             : 
     201             : # else
     202             : #  error unknown classpath configuration
     203             : # endif
     204             : 
     205             : #elif defined(ENABLE_JAVAME_CLDC1_1)
     206             : 
     207             :         // Nothing to do.
     208             : 
     209             : #else
     210             : # error unknown Java configuration
     211             : #endif
     212             : 
     213         163 :         return true;
     214             : }
     215             : 
     216             : 
     217             : /*
     218             :  * These are local overrides for various environment variables in Emacs.
     219             :  * Please do not remove this and leave it at the end of the file, where
     220             :  * Emacs will automagically detect them.
     221             :  * ---------------------------------------------------------------------
     222             :  * Local variables:
     223             :  * mode: c++
     224             :  * indent-tabs-mode: t
     225             :  * c-basic-offset: 4
     226             :  * tab-width: 4
     227             :  * End:
     228             :  * vim:noexpandtab:sw=4:ts=4:
     229             :  */

Generated by: LCOV version 1.11