Skip to content

Commit ab1f2af

Browse files
david-beaumontDavid Holmes
authored andcommitted
8366255: Remove 'package_to_module' function from imageFile.cpp
Reviewed-by: rriggs, coleenp
1 parent 57df267 commit ab1f2af

File tree

4 files changed

+6
-139
lines changed

4 files changed

+6
-139
lines changed

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

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -148,65 +148,6 @@ void ImageLocation::clear_data() {
148148
memset(_attributes, 0, sizeof(_attributes));
149149
}
150150

151-
// ImageModuleData constructor maps out sub-tables for faster access.
152-
ImageModuleData::ImageModuleData(const ImageFileReader* image_file) :
153-
_image_file(image_file),
154-
_endian(image_file->endian()) {
155-
}
156-
157-
// Release module data resource.
158-
ImageModuleData::~ImageModuleData() {
159-
}
160-
161-
162-
// Return the module in which a package resides. Returns NULL if not found.
163-
const char* ImageModuleData::package_to_module(const char* package_name) {
164-
// replace all '/' by '.'
165-
char* replaced = new char[(int) strlen(package_name) + 1];
166-
assert(replaced != NULL && "allocation failed");
167-
int i;
168-
for (i = 0; package_name[i] != '\0'; i++) {
169-
replaced[i] = package_name[i] == '/' ? '.' : package_name[i];
170-
}
171-
replaced[i] = '\0';
172-
173-
// build path /packages/<package_name>
174-
const char* radical = "/packages/";
175-
char* path = new char[(int) strlen(radical) + (int) strlen(package_name) + 1];
176-
assert(path != NULL && "allocation failed");
177-
strcpy(path, radical);
178-
strcat(path, replaced);
179-
delete[] replaced;
180-
181-
// retrieve package location
182-
ImageLocation location;
183-
bool found = _image_file->find_location(path, location);
184-
delete[] path;
185-
if (!found) {
186-
return NULL;
187-
}
188-
189-
// retrieve offsets to module name
190-
int size = (int)location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED);
191-
u1* content = new u1[size];
192-
assert(content != NULL && "allocation failed");
193-
_image_file->get_resource(location, content);
194-
u1* ptr = content;
195-
// sequence of sizeof(8) isEmpty|offset. Use the first module that is not empty.
196-
u4 offset = 0;
197-
for (i = 0; i < size; i+=8) {
198-
u4 isEmpty = _endian->get(*((u4*)ptr));
199-
ptr += 4;
200-
if (!isEmpty) {
201-
offset = _endian->get(*((u4*)ptr));
202-
break;
203-
}
204-
ptr += 4;
205-
}
206-
delete[] content;
207-
return _image_file->get_strings().get(offset);
208-
}
209-
210151
// Manage a table of open image files. This table allows multiple access points
211152
// to share an open image.
212153
ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) {
@@ -340,8 +281,7 @@ ImageFileReader* ImageFileReader::id_to_reader(u8 id) {
340281
}
341282

342283
// Constructor initializes to a closed state.
343-
ImageFileReader::ImageFileReader(const char* name, bool big_endian) :
344-
_module_data(NULL) {
284+
ImageFileReader::ImageFileReader(const char* name, bool big_endian) {
345285
// Copy the image file name.
346286
int len = (int) strlen(name) + 1;
347287
_name = new char[len];
@@ -362,10 +302,6 @@ ImageFileReader::~ImageFileReader() {
362302
delete[] _name;
363303
_name = NULL;
364304
}
365-
366-
if (_module_data != NULL) {
367-
delete _module_data;
368-
}
369305
}
370306

371307
// Open image file for read access.
@@ -414,11 +350,7 @@ bool ImageFileReader::open() {
414350
_location_bytes = _index_data + location_bytes_offset;
415351
// Compute address of index string table.
416352
_string_bytes = _index_data + string_bytes_offset;
417-
418-
// Initialize the module data
419-
_module_data = new ImageModuleData(this);
420-
// Successful open (if memory allocation succeeded).
421-
return _module_data != NULL;
353+
return true;
422354
}
423355

424356
// Close image file.
@@ -433,11 +365,6 @@ void ImageFileReader::close() {
433365
osSupport::close(_fd);
434366
_fd = -1;
435367
}
436-
437-
if (_module_data != NULL) {
438-
delete _module_data;
439-
_module_data = NULL;
440-
}
441368
}
442369

443370
// Read directly from the file.
@@ -567,8 +494,3 @@ void ImageFileReader::get_resource(ImageLocation& location, u1* uncompressed_dat
567494
assert(is_read && "error reading from image or short read");
568495
}
569496
}
570-
571-
// Return the ImageModuleData for this image
572-
ImageModuleData * ImageFileReader::get_image_module_data() {
573-
return _module_data;
574-
}

src/java.base/share/native/libjimage/imageFile.hpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -302,20 +302,6 @@ class ImageLocation {
302302
}
303303
};
304304

305-
//
306-
// Manage the image module meta data.
307-
class ImageModuleData {
308-
const ImageFileReader* _image_file; // Source image file
309-
Endian* _endian; // Endian handler
310-
311-
public:
312-
ImageModuleData(const ImageFileReader* image_file);
313-
~ImageModuleData();
314-
315-
// Return the module in which a package resides. Returns NULL if not found.
316-
const char* package_to_module(const char* package_name);
317-
};
318-
319305
// Image file header, starting at offset 0.
320306
class ImageHeader {
321307
private:
@@ -428,7 +414,6 @@ friend class ImageFileReaderTable;
428414
u4* _offsets_table; // Location offset table
429415
u1* _location_bytes; // Location attributes
430416
u1* _string_bytes; // String table
431-
ImageModuleData *_module_data; // The ImageModuleData for this image
432417

433418
ImageFileReader(const char* name, bool big_endian);
434419
~ImageFileReader();
@@ -577,9 +562,5 @@ friend class ImageFileReaderTable;
577562

578563
// Return the resource for the supplied path.
579564
void get_resource(ImageLocation& location, u1* uncompressed_data) const;
580-
581-
// Return the ImageModuleData for this image
582-
ImageModuleData * get_image_module_data();
583-
584565
};
585566
#endif // LIBJIMAGE_IMAGEFILE_HPP

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -86,23 +86,6 @@ JIMAGE_Close(JImageFile* image) {
8686
ImageFileReader::close((ImageFileReader*) image);
8787
}
8888

89-
/*
90-
* JImagePackageToModule - Given an open image file (see JImageOpen) and the name
91-
* of a package, return the name of module where the package resides. If the
92-
* package does not exist in the image file, the function returns NULL.
93-
* The resulting string does/should not have to be released. All strings are
94-
* utf-8, zero byte terminated.
95-
*
96-
* Ex.
97-
* const char* package = (*JImagePackageToModule)(image, "java/lang");
98-
* tty->print_cr(package);
99-
* -> java.base
100-
*/
101-
extern "C" JNIEXPORT const char*
102-
JIMAGE_PackageToModule(JImageFile* image, const char* package_name) {
103-
return ((ImageFileReader*) image)->get_image_module_data()->package_to_module(package_name);
104-
}
105-
10689
/*
10790
* JImageFindResource - Given an open image file (see JImageOpen), a module
10891
* name, a version string and the name of a class/resource, return location

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -93,25 +93,6 @@ JIMAGE_Close(JImageFile* jimage);
9393
typedef void (*JImageClose_t)(JImageFile* jimage);
9494

9595

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-
11596
/*
11697
* JImageFindResource - Given an open image file (see JImageOpen), a module
11798
* name, a version string and the name of a class/resource, return location

0 commit comments

Comments
 (0)