< prev index next >

src/java.base/share/native/libjimage/jimage.cpp

Print this page
rev 15121 : imported patch 8161937


  68  * file is shared by other uses, release and close is deferred until the last use
  69  * is also closed.
  70  *
  71  * Ex.
  72  *  (*JImageClose)(image);
  73  */
  74 extern "C" void JIMAGE_Close(JImageFile* image) {
  75     ImageFileReader::close((ImageFileReader*) image);
  76 }
  77 
  78 /*
  79  * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
  80  * of a package, return the name of module where the package resides. If the
  81  * package does not exist in the image file, the function returns NULL.
  82  * The resulting string does/should not have to be released. All strings are
  83  * utf-8, zero byte terminated.
  84  *
  85  * Ex.
  86  *  const char* package = (*JImagePackageToModule)(image, "java/lang");
  87  *  tty->print_cr(package);
  88  *  —> java.base
  89  */
  90 extern "C" const char* JIMAGE_PackageToModule(JImageFile* image, const char* package_name) {
  91     return ((ImageFileReader*) image)->get_image_module_data()->package_to_module(package_name);
  92 }
  93 
  94 /*
  95  * JImageFindResource - Given an open image file (see JImageOpen), a module
  96  * name, a version string and the name of a class/resource, return location
  97  * information describing the resource and its size. If no resource is found, the
  98  * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
  99  * The version number should be "9.0" and is not used in locating the resource.
 100  * The resulting location does/should not have to be released.
 101  * All strings are utf-8, zero byte terminated.
 102  *
 103  *  Ex.
 104  *   jlong size;
 105  *   JImageLocationRef location = (*JImageFindResource)(image,
 106  *                                 "java.base", "9.0", "java/lang/String.class", &size);
 107  */
 108 extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image,


 120     // If the concatenated string is too long for the buffer, return not found
 121     if (1 + moduleNameLen + 1 + nameLen + 1 > IMAGE_MAX_PATH) {
 122         return 0L;
 123     }
 124 
 125     index = 0;
 126     fullpath[index++] = '/';
 127     memcpy(&fullpath[index], module_name, moduleNameLen);
 128     index += moduleNameLen;
 129     fullpath[index++] = '/';
 130     memcpy(&fullpath[index], name, nameLen);
 131     index += nameLen;
 132     fullpath[index++] = '\0';
 133 
 134     JImageLocationRef loc =
 135             (JImageLocationRef) ((ImageFileReader*) image)->find_location_index(fullpath, (u8*) size);
 136     return loc;
 137 }
 138 
 139 /*
 140  * JImageGetResource - Given an open image file (see JImageOpen), a resource’s
 141  * location information (see JImageFindResource), a buffer of appropriate
 142  * size and the size, retrieve the bytes associated with the
 143  * resource. If the size is less than the resource size then the read is truncated.
 144  * If the size is greater than the resource size then the remainder of the buffer
 145  * is zero filled.  The function will return the actual size of the resource.
 146  *
 147  * Ex.
 148  *  jlong size;
 149  *   JImageLocationRef location = (*JImageFindResource)(image,
 150  *                                 "java.base", "9.0", "java/lang/String.class", &size);
 151  *  char* buffer = new char[size];
 152  *  (*JImageGetResource)(image, location, buffer, size);
 153  */
 154 extern "C" jlong JIMAGE_GetResource(JImageFile* image, JImageLocationRef location,
 155         char* buffer, jlong size) {
 156     ((ImageFileReader*) image)->get_resource((u4) location, (u1*) buffer);
 157     return size;
 158 }
 159 
 160 /*
 161  * JImageResourceIterator - Given an open image file (see JImageOpen), a visitor
 162  * function and a visitor argument, iterator through each of the image's resources.
 163  * The visitor function is called with the image file, the module name, the
 164  * package name, the base name, the extension and the visitor argument. The return
 165  * value of the visitor function should be true, unless an early iteration exit is
 166  * required. All strings are utf-8, zero byte terminated.file.
 167  *
 168  * Ex.
 169  *   bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version,
 170  *                  const char* package, const char* name, const char* extension, void* arg) {
 171  *     if (strcmp(extension, “class”) == 0) {
 172  *       char path[JIMAGE_MAX_PATH];
 173  *       Thread* THREAD = Thread::current();
 174  *       jio_snprintf(path, JIMAGE_MAX_PATH - 1, "/%s/%s", package, name);
 175  *       ClassLoader::compile_the_world_in(path, (Handle)arg, THREAD);
 176  *       return !HAS_PENDING_EXCEPTION;
 177  *     }
 178  *     return true;
 179  *   }
 180  *   (*JImageResourceIterator)(image, ctw_visitor, loader);
 181  */
 182 extern "C" void JIMAGE_ResourceIterator(JImageFile* image,
 183         JImageResourceVisitor_t visitor, void* arg) {
 184     ImageFileReader* imageFile = (ImageFileReader*) image;
 185     u4 nEntries = imageFile->table_length();
 186     const ImageStrings strings = imageFile->get_strings();
 187     for (u4 i = 0; i < nEntries; i++) {
 188         ImageLocation location(imageFile->get_location_data(i));
 189 
 190         u4 moduleOffset = (u4) location.get_attribute(ImageLocation::ATTRIBUTE_MODULE);
 191         if (moduleOffset == 0) {




  68  * file is shared by other uses, release and close is deferred until the last use
  69  * is also closed.
  70  *
  71  * Ex.
  72  *  (*JImageClose)(image);
  73  */
  74 extern "C" void JIMAGE_Close(JImageFile* image) {
  75     ImageFileReader::close((ImageFileReader*) image);
  76 }
  77 
  78 /*
  79  * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
  80  * of a package, return the name of module where the package resides. If the
  81  * package does not exist in the image file, the function returns NULL.
  82  * The resulting string does/should not have to be released. All strings are
  83  * utf-8, zero byte terminated.
  84  *
  85  * Ex.
  86  *  const char* package = (*JImagePackageToModule)(image, "java/lang");
  87  *  tty->print_cr(package);
  88  *  -> java.base
  89  */
  90 extern "C" const char* JIMAGE_PackageToModule(JImageFile* image, const char* package_name) {
  91     return ((ImageFileReader*) image)->get_image_module_data()->package_to_module(package_name);
  92 }
  93 
  94 /*
  95  * JImageFindResource - Given an open image file (see JImageOpen), a module
  96  * name, a version string and the name of a class/resource, return location
  97  * information describing the resource and its size. If no resource is found, the
  98  * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
  99  * The version number should be "9.0" and is not used in locating the resource.
 100  * The resulting location does/should not have to be released.
 101  * All strings are utf-8, zero byte terminated.
 102  *
 103  *  Ex.
 104  *   jlong size;
 105  *   JImageLocationRef location = (*JImageFindResource)(image,
 106  *                                 "java.base", "9.0", "java/lang/String.class", &size);
 107  */
 108 extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image,


 120     // If the concatenated string is too long for the buffer, return not found
 121     if (1 + moduleNameLen + 1 + nameLen + 1 > IMAGE_MAX_PATH) {
 122         return 0L;
 123     }
 124 
 125     index = 0;
 126     fullpath[index++] = '/';
 127     memcpy(&fullpath[index], module_name, moduleNameLen);
 128     index += moduleNameLen;
 129     fullpath[index++] = '/';
 130     memcpy(&fullpath[index], name, nameLen);
 131     index += nameLen;
 132     fullpath[index++] = '\0';
 133 
 134     JImageLocationRef loc =
 135             (JImageLocationRef) ((ImageFileReader*) image)->find_location_index(fullpath, (u8*) size);
 136     return loc;
 137 }
 138 
 139 /*
 140  * JImageGetResource - Given an open image file (see JImageOpen), a resource's
 141  * location information (see JImageFindResource), a buffer of appropriate
 142  * size and the size, retrieve the bytes associated with the
 143  * resource. If the size is less than the resource size then the read is truncated.
 144  * If the size is greater than the resource size then the remainder of the buffer
 145  * is zero filled.  The function will return the actual size of the resource.
 146  *
 147  * Ex.
 148  *  jlong size;
 149  *   JImageLocationRef location = (*JImageFindResource)(image,
 150  *                                 "java.base", "9.0", "java/lang/String.class", &size);
 151  *  char* buffer = new char[size];
 152  *  (*JImageGetResource)(image, location, buffer, size);
 153  */
 154 extern "C" jlong JIMAGE_GetResource(JImageFile* image, JImageLocationRef location,
 155         char* buffer, jlong size) {
 156     ((ImageFileReader*) image)->get_resource((u4) location, (u1*) buffer);
 157     return size;
 158 }
 159 
 160 /*
 161  * JImageResourceIterator - Given an open image file (see JImageOpen), a visitor
 162  * function and a visitor argument, iterator through each of the image's resources.
 163  * The visitor function is called with the image file, the module name, the
 164  * package name, the base name, the extension and the visitor argument. The return
 165  * value of the visitor function should be true, unless an early iteration exit is
 166  * required. All strings are utf-8, zero byte terminated.file.
 167  *
 168  * Ex.
 169  *   bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version,
 170  *                  const char* package, const char* name, const char* extension, void* arg) {
 171  *     if (strcmp(extension, "class") == 0) {
 172  *       char path[JIMAGE_MAX_PATH];
 173  *       Thread* THREAD = Thread::current();
 174  *       jio_snprintf(path, JIMAGE_MAX_PATH - 1, "/%s/%s", package, name);
 175  *       ClassLoader::compile_the_world_in(path, (Handle)arg, THREAD);
 176  *       return !HAS_PENDING_EXCEPTION;
 177  *     }
 178  *     return true;
 179  *   }
 180  *   (*JImageResourceIterator)(image, ctw_visitor, loader);
 181  */
 182 extern "C" void JIMAGE_ResourceIterator(JImageFile* image,
 183         JImageResourceVisitor_t visitor, void* arg) {
 184     ImageFileReader* imageFile = (ImageFileReader*) image;
 185     u4 nEntries = imageFile->table_length();
 186     const ImageStrings strings = imageFile->get_strings();
 187     for (u4 i = 0; i < nEntries; i++) {
 188         ImageLocation location(imageFile->get_location_data(i));
 189 
 190         u4 moduleOffset = (u4) location.get_attribute(ImageLocation::ATTRIBUTE_MODULE);
 191         if (moduleOffset == 0) {


< prev index next >