LCOV - code coverage report
Current view: top level - native/vm/gnuclasspath - java_lang_VMClassLoader.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 140 186 75.3 %
Date: 2015-06-10 18:10:59 Functions: 11 13 84.6 %

          Line data    Source code
       1             : /* src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp
       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 <assert.h>
      29             : #include <stdint.h>
      30             : 
      31             : #include "mm/memory.hpp"
      32             : 
      33             : #include "native/jni.hpp"
      34             : #include "native/llni.hpp"
      35             : #include "native/native.hpp"
      36             : 
      37             : #if defined(ENABLE_JNI_HEADERS)
      38             : # include "native/vm/include/java_lang_VMClassLoader.h"
      39             : #endif
      40             : 
      41             : #include "toolbox/logging.hpp"
      42             : #include "toolbox/list.hpp"
      43             : #include "toolbox/buffer.hpp"
      44             : 
      45             : #if defined(ENABLE_ASSERTION)
      46             : #include "vm/assertion.hpp"
      47             : #endif
      48             : 
      49             : #include "vm/array.hpp"
      50             : #include "vm/jit/builtin.hpp"
      51             : #include "vm/class.hpp"
      52             : #include "vm/classcache.hpp"
      53             : #include "vm/exceptions.hpp"
      54             : #include "vm/globals.hpp"
      55             : #include "vm/initialize.hpp"
      56             : #include "vm/javaobjects.hpp"
      57             : #include "vm/linker.hpp"
      58             : #include "vm/loader.hpp"
      59             : #include "vm/options.hpp"
      60             : #include "vm/os.hpp"
      61             : #include "vm/package.hpp"
      62             : #include "vm/primitive.hpp"
      63             : #include "vm/statistics.hpp"
      64             : #include "vm/string.hpp"
      65             : #include "vm/vm.hpp"
      66             : #include "vm/zip.hpp"
      67             : 
      68             : #include "vm/jit/asmpart.hpp"
      69             : 
      70             : #if defined(ENABLE_JVMTI)
      71             : #include "native/jvmti/cacaodbg.h"
      72             : #endif
      73             : 
      74             : 
      75             : // Native functions are exported as C functions.
      76             : extern "C" {
      77             : 
      78             : /*
      79             :  * Class:     java/lang/VMClassLoader
      80             :  * Method:    defineClass
      81             :  * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;
      82             :  */
      83         644 : JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, jobject cl, jstring name, jbyteArray data, jint offset, jint len, jobject pd)
      84             : {
      85         644 :         Utf8String     utfname;
      86             :         classinfo*     c;
      87             :         classloader_t* loader;
      88             :         uint8_t*       stream;
      89             : 
      90             : #if defined(ENABLE_JVMTI)
      91             :         jint new_class_data_len = 0;
      92             :         unsigned char* new_class_data = NULL;
      93             : #endif
      94             : 
      95             :         /* check if data was passed */
      96             : 
      97         644 :         if (data == NULL) {
      98           0 :                 exceptions_throw_nullpointerexception();
      99           0 :                 return NULL;
     100             :         }
     101             : 
     102             :         /* check the indexes passed */
     103             : 
     104         644 :         ByteArray ba(data);
     105             : 
     106         644 :         if ((offset < 0) || (len < 0) || ((offset + len) > ba.get_length())) {
     107           0 :                 exceptions_throw_arrayindexoutofboundsexception();
     108           0 :                 return NULL;
     109             :         }
     110             : 
     111             :         /* add classloader to classloader hashtable */
     112             : 
     113         644 :         loader = loader_hashtable_classloader_add((java_handle_t *) cl);
     114             : 
     115         644 :         if (name != NULL) {
     116             :                 /* convert '.' to '/' in java string */
     117             : 
     118         642 :                 utfname = JavaString((java_handle_t*) name).to_utf8_dot_to_slash();
     119             :         }
     120             :         else {
     121           2 :                 utfname = NULL;
     122             :         }
     123             : 
     124             : #if defined(ENABLE_JVMTI)
     125             :         /* XXX again this will not work because of the indirection cell for classloaders */
     126             :         assert(0);
     127             :         /* fire Class File Load Hook JVMTI event */
     128             : 
     129             :         if (jvmti)
     130             :                 jvmti_ClassFileLoadHook(utfname, len, (unsigned char *) data->data, 
     131             :                                                                 loader, (java_handle_t *) pd, 
     132             :                                                                 &new_class_data_len, &new_class_data);
     133             : #endif
     134             : 
     135             :         /* define the class */
     136             : 
     137             : #if defined(ENABLE_JVMTI)
     138             :         /* check if the JVMTI wants to modify the class */
     139             : 
     140             :         if (new_class_data == NULL)
     141             :                 c = class_define(utfname, loader, new_class_data_len, new_class_data, pd); 
     142             :         else
     143             : #endif
     144             :         {
     145         644 :                 stream = ((uint8_t *) ba.get_raw_data_ptr()) + offset;
     146         644 :                 c = class_define(utfname, loader, len, stream, (java_handle_t *) pd);
     147             :         }
     148             : 
     149         644 :         if (c == NULL)
     150           5 :                 return NULL;
     151             : 
     152             :         // REMOVEME
     153         639 :         java_handle_t* h = LLNI_classinfo_wrap(c);
     154             : 
     155             :         // Set ProtectionDomain.
     156         639 :         java_lang_Class jlc(h);
     157         639 :         jlc.set_pd(pd);
     158             : 
     159         639 :         return (jclass) jlc.get_handle();
     160             : }
     161             : 
     162             : 
     163             : /*
     164             :  * Class:     java/lang/VMClassLoader
     165             :  * Method:    getPrimitiveClass
     166             :  * Signature: (C)Ljava/lang/Class;
     167             :  */
     168         469 : JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_getPrimitiveClass(JNIEnv *env, jclass clazz, jchar type)
     169             : {
     170             :         classinfo *c;
     171             : 
     172         469 :         c = Primitive::get_class_by_char(type);
     173             : 
     174         469 :         if (c == NULL) {
     175           0 :                 exceptions_throw_classnotfoundexception(utf8::null);
     176           0 :                 return NULL;
     177             :         }
     178             : 
     179         469 :         return (jclass) LLNI_classinfo_wrap(c);
     180             : }
     181             : 
     182             : 
     183             : /*
     184             :  * Class:     java/lang/VMClassLoader
     185             :  * Method:    resolveClass
     186             :  * Signature: (Ljava/lang/Class;)V
     187             :  */
     188           0 : JNIEXPORT void JNICALL Java_java_lang_VMClassLoader_resolveClass(JNIEnv *env, jclass clazz, jclass c)
     189             : {
     190             :         classinfo *ci;
     191             : 
     192           0 :         ci = LLNI_classinfo_unwrap(c);
     193             : 
     194           0 :         if (!ci) {
     195           0 :                 exceptions_throw_nullpointerexception();
     196           0 :                 return;
     197             :         }
     198             : 
     199             :         /* link the class */
     200             : 
     201           0 :         if (!(ci->state & CLASS_LINKED))
     202           0 :                 (void) link_class(ci);
     203             : 
     204           0 :         return;
     205             : }
     206             : 
     207             : 
     208             : /*
     209             :  * Class:     java/lang/VMClassLoader
     210             :  * Method:    loadClass
     211             :  * Signature: (Ljava/lang/String;Z)Ljava/lang/Class;
     212             :  */
     213        1384 : JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_loadClass(JNIEnv *env, jclass clazz, jstring name, jboolean resolve)
     214             : {
     215        1384 :         if (name == NULL) {
     216           0 :                 exceptions_throw_nullpointerexception();
     217           0 :                 return NULL;
     218             :         }
     219             : 
     220             :         /* create utf string in which '.' is replaced by '/' */
     221             : 
     222        1384 :         Utf8String u = JavaString((java_handle_t*) name).to_utf8_dot_to_slash();
     223             : 
     224             :         /* load class */
     225             : 
     226        1384 :         classinfo *c = load_class_bootstrap(u);
     227             : 
     228        1384 :         if (c == NULL)
     229         624 :                 return NULL;
     230             : 
     231             :         /* resolve class -- if requested */
     232             : 
     233             : /*      if (resolve) */
     234         760 :                 if (!link_class(c))
     235           0 :                         return NULL;
     236             : 
     237         760 :         return (jclass) LLNI_classinfo_wrap(c);
     238             : }
     239             : 
     240             : 
     241             : /*
     242             :  * Class:     java/lang/VMClassLoader
     243             :  * Method:    nativeGetResources
     244             :  * Signature: (Ljava/lang/String;)Ljava/util/Vector;
     245             :  */
     246          12 : JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv *env, jclass clazz, jstring name)
     247             : {
     248             :         java_handle_t        *o;         /* vector being created     */
     249             :         methodinfo           *m;         /* "add" method of vector   */
     250             :         java_handle_t        *path;      /* path to be added         */
     251          12 :         Utf8String            utfname;   /* utf to look for          */
     252             :         const char           *namestart; /* start of name to use     */
     253             :         char                 *tmppath;   /* temporary buffer         */
     254             :         int32_t               namelen;   /* length of name to use    */
     255             :         int32_t               searchlen; /* length of name to search */
     256             :         int32_t               bufsize;   /* size of buffer allocated */
     257             :         int32_t               pathlen;   /* name of path to assemble */
     258             :         struct stat           buf;       /* buffer for stat          */
     259             :         jboolean              ret;       /* return value of "add"    */
     260             : 
     261             :         // Get current list of classpath entries.
     262          12 :         SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
     263             : 
     264             :         /* get the resource name as utf string */
     265             : 
     266          12 :         utfname = JavaString((java_handle_t*) name).to_utf8();
     267             : 
     268          12 :         if (utfname == NULL)
     269           0 :                 return NULL;
     270             : 
     271             :         /* copy it to a char buffer */
     272             : 
     273          12 :         Buffer<> buffer;
     274          12 :         buffer.write(utfname);
     275             : 
     276          12 :         namelen   = utfname.size();
     277          12 :         searchlen = namelen;
     278          12 :         bufsize   = namelen + strlen("0");
     279          12 :         namestart = buffer.c_str();
     280             : 
     281             :         /* skip leading '/' */
     282             : 
     283          12 :         if (namestart[0] == '/') {
     284           0 :                 namestart++;
     285           0 :                 namelen--;
     286           0 :                 searchlen--;
     287             :         }
     288             : 
     289             :         /* remove trailing `.class' */
     290             : 
     291          12 :         if (namelen >= 6 && strcmp(namestart + (namelen - 6), ".class") == 0) {
     292           0 :                 searchlen -= 6;
     293             :         }
     294             : 
     295             :         /* create a new needle to look for, if necessary */
     296             : 
     297          12 :         if (searchlen != bufsize-1) {
     298           0 :                 utfname = Utf8String::from_utf8(namestart, searchlen);
     299           0 :                 if (utfname == NULL)
     300           0 :                         goto return_NULL;
     301             :         }
     302             :                         
     303             :         /* new Vector() */
     304             : 
     305          12 :         o = native_new_and_init(class_java_util_Vector);
     306             : 
     307          12 :         if (o == NULL)
     308           0 :                 goto return_NULL;
     309             : 
     310             :         /* get Vector.add() method */
     311             : 
     312             :         m = class_resolveclassmethod(class_java_util_Vector,
     313             :                                      utf8::add,
     314             :                                      Utf8String::from_utf8("(Ljava/lang/Object;)Z"),
     315             :                                      NULL,
     316          12 :                                      true);
     317             : 
     318          12 :         if (m == NULL)
     319           0 :                 goto return_NULL;
     320             : 
     321             :         /* iterate over all classpath entries */
     322             : 
     323          36 :         for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
     324          24 :                 list_classpath_entry* lce = *it;
     325             : 
     326             :                 /* clear path pointer */
     327          24 :                 path = NULL;
     328             : 
     329             : #if defined(ENABLE_ZLIB)
     330          24 :                 if (lce->type == CLASSPATH_ARCHIVE && lce->zip->find(utfname)) {
     331          12 :                         pathlen = strlen("jar:file://") + lce->pathlen + strlen("!/") + namelen + strlen("0");
     332             : 
     333          12 :                         tmppath = MNEW(char, pathlen);
     334             : 
     335          12 :                         sprintf(tmppath, "jar:file://%s!/%s", lce->path, namestart);
     336             :                         path = JavaString::from_utf8(tmppath),
     337             : 
     338          12 :                         MFREE(tmppath, char, pathlen);
     339             :                 } else {
     340             : #endif /* defined(ENABLE_ZLIB) */
     341          12 :                         pathlen = strlen("file://") + lce->pathlen + namelen + strlen("0");
     342             : 
     343          12 :                         tmppath = MNEW(char, pathlen);
     344             : 
     345          12 :                         sprintf(tmppath, "file://%s%s", lce->path, namestart);
     346             : 
     347             :                         /* Does this file exist? */
     348             : 
     349          12 :                         if (stat(tmppath + strlen("file://") - 1, &buf) == 0)
     350           0 :                                 if (!S_ISDIR(buf.st_mode))
     351           0 :                                         path = JavaString::from_utf8(tmppath);
     352             : 
     353          12 :                         MFREE(tmppath, char, pathlen);
     354             : #if defined(ENABLE_ZLIB)
     355             :                 }
     356             : #endif
     357             : 
     358             :                 /* if a resource was found, add it to the vector */
     359             : 
     360          24 :                 if (path != NULL) {
     361          12 :                         ret = vm_call_method_int(m, o, path);
     362             : 
     363          12 :                         if (exceptions_get_exception() != NULL)
     364           0 :                                 goto return_NULL;
     365             : 
     366          12 :                         if (ret == 0) 
     367           0 :                                 goto return_NULL;
     368             :                 }
     369             :         }
     370             : 
     371          12 :         return (jobject) o;
     372             : 
     373             : return_NULL:
     374           0 :         return NULL;
     375             : }
     376             : 
     377             : 
     378             : /*
     379             :  * Class:     java/lang/VMClassLoader
     380             :  * Method:    getStystemAssertionStatus
     381             :  * Signature: ()Z
     382             :  */
     383           0 : JNIEXPORT jboolean JNICALL Java_java_lang_VMClassLoader_getSystemAssertionStatus(JNIEnv *env, jclass clazz)
     384             : {
     385             : #if defined(ENABLE_ASSERTION)
     386           0 :         return assertion_system_enabled;
     387             : #else
     388             :         return false;
     389             : #endif
     390             : }
     391             : 
     392             : /*
     393             :  * Class:     java/lang/VMClassLoader
     394             :  * Method:    defaultAssertionStatus
     395             :  * Signature: ()Z
     396             :  */
     397         178 : JNIEXPORT jboolean JNICALL Java_java_lang_VMClassLoader_defaultAssertionStatus(JNIEnv *env, jclass clazz)
     398             : {
     399             : #if defined(ENABLE_ASSERTION)
     400         178 :         return assertion_user_enabled;
     401             : #else
     402             :         return false;
     403             : #endif
     404             : }
     405             : 
     406             : /*
     407             :  * Class:     java/lang/VMClassLoader
     408             :  * Method:    packageAssertionStatus
     409             :  * Signature: (Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map;
     410             :  */
     411         141 : JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(JNIEnv *env, jclass clazz, jobject jtrue, jobject jfalse)
     412             : {
     413             :         java_handle_t     *hm;
     414             : #if defined(ENABLE_ASSERTION)
     415             :         java_handle_t     *js;
     416             :         methodinfo        *m;
     417             : #endif
     418             : 
     419             :         /* new HashMap() */
     420             : 
     421         141 :         hm = native_new_and_init(class_java_util_HashMap);
     422         141 :         if (hm == NULL) {
     423           0 :                 return NULL;
     424             :         }
     425             : 
     426             : #if defined(ENABLE_ASSERTION)
     427             :         /* if nothing todo, return now */
     428             : 
     429         141 :         if (assertion_package_count == 0) {
     430         131 :                 return (jobject) hm;
     431             :         }
     432             : 
     433             :         /* get HashMap.put method */
     434             : 
     435             :         m = class_resolveclassmethod(class_java_util_HashMap,
     436             :                                      utf8::put,
     437             :                                      Utf8String::from_utf8("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
     438             :                                      NULL,
     439          10 :                                      true);
     440             : 
     441          10 :         if (m == NULL) {
     442           0 :                 return NULL;
     443             :         }
     444             : 
     445          20 :         for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
     446          10 :                 assertion_name_t* item = *it;
     447             : 
     448          10 :                 if (item->package == false)
     449           0 :                         continue;
     450             :                 
     451          10 :                 if (strcmp(item->name, "") == 0) {
     452             :                         /* unnamed package wanted */
     453           0 :                         js = NULL;
     454             :                 }
     455             :                 else {
     456          10 :                         js = JavaString::from_utf8(item->name);
     457          10 :                         if (js == NULL) {
     458           0 :                                 return NULL;
     459             :                         }
     460             :                 }
     461             : 
     462          10 :                 if (item->enabled == true) {
     463           5 :                         vm_call_method(m, hm, js, jtrue);
     464             :                 }
     465             :                 else {
     466           5 :                         vm_call_method(m, hm, js, jfalse);
     467             :                 }
     468             :         }
     469             : #endif
     470             : 
     471          10 :         return (jobject) hm;
     472             : }
     473             : 
     474             : /*
     475             :  * Class:     java/lang/VMClassLoader
     476             :  * Method:    classAssertionStatus
     477             :  * Signature: (Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map;
     478             :  */
     479         141 : JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNIEnv *env, jclass clazz, jobject jtrue, jobject jfalse)
     480             : {
     481             :         java_handle_t     *hm;
     482             : #if defined(ENABLE_ASSERTION)
     483             :         java_handle_t     *js;
     484             :         methodinfo        *m;
     485             : #endif
     486             : 
     487             :         /* new HashMap() */
     488             : 
     489         141 :         hm = native_new_and_init(class_java_util_HashMap);
     490         141 :         if (hm == NULL) {
     491           0 :                 return NULL;
     492             :         }
     493             : 
     494             : #if defined(ENABLE_ASSERTION)
     495             :         /* if nothing todo, return now */
     496             : 
     497         141 :         if (assertion_class_count == 0) {
     498         131 :                 return (jobject) hm;
     499             :         }
     500             : 
     501             :         /* get HashMap.put method */
     502             : 
     503             :         m = class_resolveclassmethod(class_java_util_HashMap,
     504             :                                  utf8::put,
     505             :                                  Utf8String::from_utf8("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
     506             :                                  NULL,
     507          10 :                                  true);
     508             : 
     509          10 :         if (m == NULL) {
     510           0 :                 return NULL;
     511             :         }
     512             : 
     513          20 :         for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
     514          10 :                 assertion_name_t* item = *it;
     515             : 
     516          10 :                 if (item->package == true)
     517           0 :                         continue;
     518             : 
     519          10 :                 js = JavaString::from_utf8(item->name);
     520          10 :                 if (js == NULL) {
     521           0 :                         return NULL;
     522             :                 }
     523             : 
     524          10 :                 if (item->enabled == true) {
     525           5 :                         vm_call_method(m, hm, js, jtrue);
     526             :                 }
     527             :                 else {
     528           5 :                         vm_call_method(m, hm, js, jfalse);
     529             :                 }
     530             :         }
     531             : #endif
     532             : 
     533          10 :         return (jobject) hm;
     534             : }
     535             : 
     536             : 
     537             : /*
     538             :  * Class:     java/lang/VMClassLoader
     539             :  * Method:    findLoadedClass
     540             :  * Signature: (Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;
     541             :  */
     542        1438 : JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_findLoadedClass(JNIEnv *env, jclass clazz, jobject loader, jstring name)
     543             : {
     544             :         /* XXX is it correct to add the classloader to the hashtable here? */
     545             : 
     546        1438 :         classloader_t *cl = loader_hashtable_classloader_add((java_handle_t *) loader);
     547             : 
     548             :         /* replace `.' by `/', this is required by the classcache */
     549             : 
     550        1438 :         Utf8String u = JavaString((java_handle_t*) name).to_utf8_dot_to_slash();
     551             : 
     552             :         /* lookup for defining classloader */
     553             : 
     554        1438 :         classinfo *c = classcache_lookup_defined(cl, u);
     555             : 
     556             :         /* if not found, lookup for initiating classloader */
     557             : 
     558        1438 :         if (c == NULL)
     559        1436 :                 c = classcache_lookup(cl, u);
     560             : 
     561        1438 :         return (jclass) LLNI_classinfo_wrap(c);
     562             : }
     563             : 
     564             : /*
     565             :  * Class:     java/lang/VMClassLoader
     566             :  * Method:    getBootPackage
     567             :  * Signature: (Ljava/lang/String;)Ljava/lang/Package;
     568             :  */
     569         269 : JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_getBootPackage(JNIEnv *env, jclass clazz, jstring name)
     570             : {
     571         269 :         Utf8String u(JavaString((java_handle_t *) name).to_utf8());
     572         269 :         if (!Package::find(u))
     573         268 :                 return NULL;
     574             : 
     575           1 :         classinfo *c = LLNI_classinfo_unwrap(clazz);
     576             :         methodinfo *m = class_resolveclassmethod(
     577             :                 c,
     578             :                 Utf8String::from_utf8("createBootPackage"),
     579             :                 Utf8String::from_utf8("(Ljava/lang/String;)Ljava/lang/Package;"),
     580             :                 NULL,
     581           1 :                 true);
     582           1 :         assert(m);
     583             : 
     584           1 :         java_handle_t *hm = vm_call_method(m, name);
     585           1 :         return (jobject) hm;
     586             : }
     587             : 
     588             : /*
     589             :  * Class:     java/lang/VMClassLoader
     590             :  * Method:    getBootPackages
     591             :  * Signature: ()[Ljava/lang/Package;
     592             :  */
     593           1 : JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_getBootPackages(JNIEnv *env, jclass clazz)
     594             : {
     595           1 :         classinfo *c = LLNI_classinfo_unwrap(clazz);
     596             :         methodinfo *m = class_resolveclassmethod(
     597             :                 c,
     598             :                 Utf8String::from_utf8("createBootPackage"),
     599             :                 Utf8String::from_utf8("(Ljava/lang/String;)Ljava/lang/Package;"),
     600             :                 NULL,
     601           1 :                 true);
     602           1 :         assert(m);
     603             : 
     604           1 :         AnyClassLocker<Package> lock;
     605           1 :         const std::set<Utf8String> &packages(Package::packages());
     606           1 :         int num = packages.size();
     607             : 
     608           1 :         classinfo *pc = load_class_bootstrap(Utf8String::from_utf8("java/lang/Package"));
     609           1 :         if (!pc)
     610           0 :                 return NULL;
     611           1 :         ObjectArray result(num, pc);
     612           1 :         std::set<Utf8String>::const_iterator it = packages.begin();
     613          44 :         for (int i=0; it != packages.end(); ++it, i++) {
     614          43 :                 JavaString package_name = JavaString::from_utf8(*it);
     615          43 :                 java_handle_t *hs = package_name;
     616          43 :                 if (!hs)
     617           0 :                         return NULL;
     618          43 :                 java_handle_t *h = vm_call_method(m, package_name);
     619          43 :                 if (!h)
     620           0 :                         return NULL;
     621          43 :                 result.set_element(i, h);
     622             :         }
     623           1 :         return result.get_handle();
     624             : }
     625             : 
     626             : } // extern "C"
     627             : 
     628             : 
     629             : /* native methods implemented by this file ************************************/
     630             : 
     631             : static JNINativeMethod methods[] = {
     632             :         { (char*) "defineClass",                (char*) "(Ljava/lang/ClassLoader;Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class;", (void*) (uintptr_t) &Java_java_lang_VMClassLoader_defineClass                },
     633             :         { (char*) "getPrimitiveClass",          (char*) "(C)Ljava/lang/Class;",                                                                             (void*) (uintptr_t) &Java_java_lang_VMClassLoader_getPrimitiveClass          },
     634             :         { (char*) "resolveClass",               (char*) "(Ljava/lang/Class;)V",                                                                             (void*) (uintptr_t) &Java_java_lang_VMClassLoader_resolveClass               },
     635             :         { (char*) "loadClass",                  (char*) "(Ljava/lang/String;Z)Ljava/lang/Class;",                                                           (void*) (uintptr_t) &Java_java_lang_VMClassLoader_loadClass                  },
     636             :         { (char*) "nativeGetResources",         (char*) "(Ljava/lang/String;)Ljava/util/Vector;",                                                           (void*) (uintptr_t) &Java_java_lang_VMClassLoader_nativeGetResources         },
     637             :         { (char*) "getSystemAssertionStatus",   (char*) "()Z",                                                                                              (void*) (uintptr_t) &Java_java_lang_VMClassLoader_getSystemAssertionStatus   },
     638             :         { (char*) "defaultAssertionStatus",     (char*) "()Z",                                                                                              (void*) (uintptr_t) &Java_java_lang_VMClassLoader_defaultAssertionStatus },
     639             :         { (char*) "packageAssertionStatus0",    (char*) "(Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map;",                                          (void*) (uintptr_t) &Java_java_lang_VMClassLoader_packageAssertionStatus0    },
     640             :         { (char*) "classAssertionStatus0",      (char*) "(Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/util/Map;",                                          (void*) (uintptr_t) &Java_java_lang_VMClassLoader_classAssertionStatus0      },
     641             :         { (char*) "findLoadedClass",            (char*) "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;",                                     (void*) (uintptr_t) &Java_java_lang_VMClassLoader_findLoadedClass            },
     642             :         { (char*) "getBootPackage",             (char*) "(Ljava/lang/String;)Ljava/lang/Package;",                                                          (void*) (uintptr_t) &Java_java_lang_VMClassLoader_getBootPackage             },
     643             :         { (char*) "getBootPackages",            (char*) "()[Ljava/lang/Package;",                                                                           (void*) (uintptr_t) &Java_java_lang_VMClassLoader_getBootPackages            },
     644             : };
     645             : 
     646             : 
     647             : /* _Jv_java_lang_VMClassLoader_init ********************************************
     648             : 
     649             :    Register native functions.
     650             : 
     651             : *******************************************************************************/
     652             : 
     653         163 : void _Jv_java_lang_VMClassLoader_init(void)
     654             : {
     655         163 :         Utf8String u = Utf8String::from_utf8("java/lang/VMClassLoader");
     656             : 
     657         163 :         NativeMethods& nm = VM::get_current()->get_nativemethods();
     658         163 :         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
     659         163 : }
     660             : 
     661             : 
     662             : /*
     663             :  * These are local overrides for various environment variables in Emacs.
     664             :  * Please do not remove this and leave it at the end of the file, where
     665             :  * Emacs will automagically detect them.
     666             :  * ---------------------------------------------------------------------
     667             :  * Local variables:
     668             :  * mode: c++
     669             :  * indent-tabs-mode: t
     670             :  * c-basic-offset: 4
     671             :  * tab-width: 4
     672             :  * End:
     673             :  * vim:noexpandtab:sw=4:ts=4:
     674             :  */

Generated by: LCOV version 1.11