55 * JImageOpen - Given the supplied full path file name, open an image file. This
56 * function will also initialize tables and retrieve meta-data necessary to
57 * satisfy other functions in the API. If the image file has been previously
58 * open, a new open request will share memory and resources used by the previous
59 * open. A call to JImageOpen should be balanced by a call to JImageClose, to
60 * release memory and resources used. If the image file is not found or cannot
61 * be open, then NULL is returned and error will contain a reason for the
62 * failure; a positive value for a system error number, negative for a jimage
63 * specific error (see JImage Error Codes.)
64 *
65 * Ex.
66 * jint error;
67 * JImageFile* jimage = (*JImageOpen)(JAVA_HOME "lib/modules", &error);
68 * if (image == NULL) {
69 * tty->print_cr("JImage failed to open: %d", error);
70 * ...
71 * }
72 * ...
73 */
74
75 extern "C" JNIEXPORT JImageFile* JNICALL
76 JIMAGE_Open(const char *name, jint* error);
77
78 typedef JImageFile* (*JImageOpen_t)(const char *name, jint* error);
79
80 /*
81 * JImageClose - Given the supplied open image file (see JImageOpen), release
82 * memory and resources used by the open file and close the file. If the image
83 * file is shared by other uses, release and close is deferred until the last use
84 * is also closed.
85 *
86 * Ex.
87 * (*JImageClose)(image);
88 */
89
90 extern "C" JNIEXPORT void JNICALL
91 JIMAGE_Close(JImageFile* jimage);
92
93 typedef void (*JImageClose_t)(JImageFile* jimage);
94
95
96 /*
97 * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
98 * of a package, return the name of module where the package resides. If the
99 * package does not exist in the image file, the function returns NULL.
100 * The resulting string does/should not have to be released. All strings are
101 * utf-8, zero byte terminated.
102 *
103 * Ex.
104 * const char* package = (*JImagePackageToModule)(image, "java/lang");
105 * tty->print_cr(package);
106 * -> java.base
107 */
108
109 extern "C" JNIEXPORT const char * JNICALL
110 JIMAGE_PackageToModule(JImageFile* jimage, const char* package_name);
111
112 typedef const char* (*JImagePackageToModule_t)(JImageFile* jimage, const char* package_name);
113
114
115 /*
116 * JImageFindResource - Given an open image file (see JImageOpen), a module
117 * name, a version string and the name of a class/resource, return location
118 * information describing the resource and its size. If no resource is found, the
119 * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
120 * The version number should be "9.0" and is not used in locating the resource.
121 * The resulting location does/should not have to be released.
122 * All strings are utf-8, zero byte terminated.
123 *
124 * Ex.
125 * jlong size;
126 * JImageLocationRef location = (*JImageFindResource)(image,
127 * "java.base", "9.0", "java/lang/String.class", &size);
128 */
129 extern "C" JNIEXPORT JImageLocationRef JIMAGE_FindResource(JImageFile* jimage,
133 typedef JImageLocationRef(*JImageFindResource_t)(JImageFile* jimage,
134 const char* module_name, const char* version, const char* name,
135 jlong* size);
136
137
138 /*
139 * JImageGetResource - Given an open image file (see JImageOpen), a resource's
140 * location information (see JImageFindResource), a buffer of appropriate
141 * size and the size, retrieve the bytes associated with the
142 * resource. If the size is less than the resource size then the read is truncated.
143 * If the size is greater than the resource size then the remainder of the buffer
144 * is zero filled. The function will return the actual size of the resource.
145 *
146 * Ex.
147 * jlong size;
148 * JImageLocationRef location = (*JImageFindResource)(image,
149 * "java.base", "9.0", "java/lang/String.class", &size);
150 * char* buffer = new char[size];
151 * (*JImageGetResource)(image, location, buffer, size);
152 */
153 extern "C" JNIEXPORT jlong JNICALL
154 JIMAGE_GetResource(JImageFile* jimage, JImageLocationRef location,
155 char* buffer, jlong size);
156
157 typedef jlong(*JImageGetResource_t)(JImageFile* jimage, JImageLocationRef location,
158 char* buffer, jlong size);
159
160
161 /*
162 * JImageResourceIterator - Given an open image file (see JImageOpen), a visitor
163 * function and a visitor argument, iterator through each of the image's resources.
164 * The visitor function is called with the image file, the module name, the
165 * package name, the base name, the extension and the visitor argument. The return
166 * value of the visitor function should be true, unless an early iteration exit is
167 * required. All strings are utf-8, zero byte terminated.file.
168 *
169 * Ex.
170 * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version,
171 * const char* package, const char* name, const char* extension, void* arg) {
172 * if (strcmp(extension, "class") == 0) {
173 * char path[JIMAGE_MAX_PATH];
174 * Thread* THREAD = Thread::current();
175 * jio_snprintf(path, JIMAGE_MAX_PATH - 1, "/%s/%s", package, name);
176 * ClassLoader::compile_the_world_in(path, (Handle)arg, THREAD);
177 * return !HAS_PENDING_EXCEPTION;
178 * }
179 * return true;
180 * }
181 * (*JImageResourceIterator)(image, ctw_visitor, loader);
182 */
183
184 typedef bool (*JImageResourceVisitor_t)(JImageFile* jimage,
185 const char* module_name, const char* version, const char* package,
186 const char* name, const char* extension, void* arg);
187
188 extern "C" JNIEXPORT void JNICALL
189 JIMAGE_ResourceIterator(JImageFile* jimage,
190 JImageResourceVisitor_t visitor, void *arg);
191
192 typedef void (*JImageResourceIterator_t)(JImageFile* jimage,
193 JImageResourceVisitor_t visitor, void* arg);
194
195 /*
196 * JIMAGE_ResourcePath- Given an open image file, a location reference, a buffer
197 * and a maximum buffer size, copy the path of the resource into the buffer.
198 * Returns false if not a valid location reference.
199 *
200 * Ex.
201 * JImageLocationRef location = ...
202 * char path[JIMAGE_MAX_PATH];
203 * (*JImageResourcePath)(image, location, path, JIMAGE_MAX_PATH);
204 */
205 extern "C" JNIEXPORT bool JNICALL
206 JIMAGE_ResourcePath(JImageFile* image, JImageLocationRef locationRef,
207 char* path, size_t max);
208
209 typedef bool (*JImage_ResourcePath_t)(JImageFile* jimage, JImageLocationRef location,
210 char* buffer, jlong size);
|
55 * JImageOpen - Given the supplied full path file name, open an image file. This
56 * function will also initialize tables and retrieve meta-data necessary to
57 * satisfy other functions in the API. If the image file has been previously
58 * open, a new open request will share memory and resources used by the previous
59 * open. A call to JImageOpen should be balanced by a call to JImageClose, to
60 * release memory and resources used. If the image file is not found or cannot
61 * be open, then NULL is returned and error will contain a reason for the
62 * failure; a positive value for a system error number, negative for a jimage
63 * specific error (see JImage Error Codes.)
64 *
65 * Ex.
66 * jint error;
67 * JImageFile* jimage = (*JImageOpen)(JAVA_HOME "lib/modules", &error);
68 * if (image == NULL) {
69 * tty->print_cr("JImage failed to open: %d", error);
70 * ...
71 * }
72 * ...
73 */
74
75 extern "C" JNIEXPORT JImageFile*
76 JIMAGE_Open(const char *name, jint* error);
77
78 typedef JImageFile* (*JImageOpen_t)(const char *name, jint* error);
79
80 /*
81 * JImageClose - Given the supplied open image file (see JImageOpen), release
82 * memory and resources used by the open file and close the file. If the image
83 * file is shared by other uses, release and close is deferred until the last use
84 * is also closed.
85 *
86 * Ex.
87 * (*JImageClose)(image);
88 */
89
90 extern "C" JNIEXPORT void
91 JIMAGE_Close(JImageFile* jimage);
92
93 typedef void (*JImageClose_t)(JImageFile* jimage);
94
95
96 /*
97 * JImagePackageToModule - Given an open image file (see JImageOpen) and the name
98 * of a package, return the name of module where the package resides. If the
99 * package does not exist in the image file, the function returns NULL.
100 * The resulting string does/should not have to be released. All strings are
101 * utf-8, zero byte terminated.
102 *
103 * Ex.
104 * const char* package = (*JImagePackageToModule)(image, "java/lang");
105 * tty->print_cr(package);
106 * -> java.base
107 */
108
109 extern "C" JNIEXPORT const char *
110 JIMAGE_PackageToModule(JImageFile* jimage, const char* package_name);
111
112 typedef const char* (*JImagePackageToModule_t)(JImageFile* jimage, const char* package_name);
113
114
115 /*
116 * JImageFindResource - Given an open image file (see JImageOpen), a module
117 * name, a version string and the name of a class/resource, return location
118 * information describing the resource and its size. If no resource is found, the
119 * function returns JIMAGE_NOT_FOUND and the value of size is undefined.
120 * The version number should be "9.0" and is not used in locating the resource.
121 * The resulting location does/should not have to be released.
122 * All strings are utf-8, zero byte terminated.
123 *
124 * Ex.
125 * jlong size;
126 * JImageLocationRef location = (*JImageFindResource)(image,
127 * "java.base", "9.0", "java/lang/String.class", &size);
128 */
129 extern "C" JNIEXPORT JImageLocationRef JIMAGE_FindResource(JImageFile* jimage,
133 typedef JImageLocationRef(*JImageFindResource_t)(JImageFile* jimage,
134 const char* module_name, const char* version, const char* name,
135 jlong* size);
136
137
138 /*
139 * JImageGetResource - Given an open image file (see JImageOpen), a resource's
140 * location information (see JImageFindResource), a buffer of appropriate
141 * size and the size, retrieve the bytes associated with the
142 * resource. If the size is less than the resource size then the read is truncated.
143 * If the size is greater than the resource size then the remainder of the buffer
144 * is zero filled. The function will return the actual size of the resource.
145 *
146 * Ex.
147 * jlong size;
148 * JImageLocationRef location = (*JImageFindResource)(image,
149 * "java.base", "9.0", "java/lang/String.class", &size);
150 * char* buffer = new char[size];
151 * (*JImageGetResource)(image, location, buffer, size);
152 */
153 extern "C" JNIEXPORT jlong
154 JIMAGE_GetResource(JImageFile* jimage, JImageLocationRef location,
155 char* buffer, jlong size);
156
157 typedef jlong(*JImageGetResource_t)(JImageFile* jimage, JImageLocationRef location,
158 char* buffer, jlong size);
159
160
161 /*
162 * JImageResourceIterator - Given an open image file (see JImageOpen), a visitor
163 * function and a visitor argument, iterator through each of the image's resources.
164 * The visitor function is called with the image file, the module name, the
165 * package name, the base name, the extension and the visitor argument. The return
166 * value of the visitor function should be true, unless an early iteration exit is
167 * required. All strings are utf-8, zero byte terminated.file.
168 *
169 * Ex.
170 * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version,
171 * const char* package, const char* name, const char* extension, void* arg) {
172 * if (strcmp(extension, "class") == 0) {
173 * char path[JIMAGE_MAX_PATH];
174 * Thread* THREAD = Thread::current();
175 * jio_snprintf(path, JIMAGE_MAX_PATH - 1, "/%s/%s", package, name);
176 * ClassLoader::compile_the_world_in(path, (Handle)arg, THREAD);
177 * return !HAS_PENDING_EXCEPTION;
178 * }
179 * return true;
180 * }
181 * (*JImageResourceIterator)(image, ctw_visitor, loader);
182 */
183
184 typedef bool (*JImageResourceVisitor_t)(JImageFile* jimage,
185 const char* module_name, const char* version, const char* package,
186 const char* name, const char* extension, void* arg);
187
188 extern "C" JNIEXPORT void
189 JIMAGE_ResourceIterator(JImageFile* jimage,
190 JImageResourceVisitor_t visitor, void *arg);
191
192 typedef void (*JImageResourceIterator_t)(JImageFile* jimage,
193 JImageResourceVisitor_t visitor, void* arg);
194
195 /*
196 * JIMAGE_ResourcePath- Given an open image file, a location reference, a buffer
197 * and a maximum buffer size, copy the path of the resource into the buffer.
198 * Returns false if not a valid location reference.
199 *
200 * Ex.
201 * JImageLocationRef location = ...
202 * char path[JIMAGE_MAX_PATH];
203 * (*JImageResourcePath)(image, location, path, JIMAGE_MAX_PATH);
204 */
205 extern "C" JNIEXPORT bool
206 JIMAGE_ResourcePath(JImageFile* image, JImageLocationRef locationRef,
207 char* path, size_t max);
208
209 typedef bool (*JImage_ResourcePath_t)(JImageFile* jimage, JImageLocationRef location,
210 char* buffer, jlong size);
|