comparison src/java.base/share/native/libjimage/imageFile.cpp @ 14563:2891d078c753

8141571: jdk/internal/jimage/JImageReadTest.java crashing in msvcr120.dll Summary: add asserts to diagnose Reviewed-by: jlaskey
author rriggs
date Fri, 13 Nov 2015 12:00:23 -0500
parents 40cb3080b3dd
children db40b83b1071 384f4b699387
comparison
equal deleted inserted replaced
8:a2eaa635806b 9:31880f365d81
147 ImageLocation location; 147 ImageLocation location;
148 bool found = image_file->find_location(module_data_name, location); 148 bool found = image_file->find_location(module_data_name, location);
149 if (found) { 149 if (found) {
150 u8 data_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); 150 u8 data_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED);
151 _data = new u1[(size_t)data_size]; 151 _data = new u1[(size_t)data_size];
152 assert(_data != NULL && "allocation failed");
152 _image_file->get_resource(location, _data); 153 _image_file->get_resource(location, _data);
153 // Map out the header. 154 // Map out the header.
154 _header = (Header*)_data; 155 _header = (Header*)_data;
155 // Get the package to module entry count. 156 // Get the package to module entry count.
156 u4 ptm_count = _header->ptm_count(_endian); 157 u4 ptm_count = _header->ptm_count(_endian);
252 return NULL; 253 return NULL;
253 } 254 }
254 // Construct an array of all the package entries. 255 // Construct an array of all the package entries.
255 u4 count = data->package_count(_endian); 256 u4 count = data->package_count(_endian);
256 const char** packages = new const char*[count + 1]; 257 const char** packages = new const char*[count + 1];
258 assert(packages != NULL && "allocation failed");
257 s4 package_offset = data->package_offset(_endian); 259 s4 package_offset = data->package_offset(_endian);
258 for (u4 i = 0; i < count; i++) { 260 for (u4 i = 0; i < count; i++) {
259 u4 package_name_offset = mtp_package(package_offset + i); 261 u4 package_name_offset = mtp_package(package_offset + i);
260 const char* package_name = get_string(package_name_offset); 262 const char* package_name = get_string(package_name_offset);
261 packages[i] = package_name; 263 packages[i] = package_name;
269 271
270 // Manage a table of open image files. This table allows multiple access points 272 // Manage a table of open image files. This table allows multiple access points
271 // to share an open image. 273 // to share an open image.
272 ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) { 274 ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) {
273 _table = new ImageFileReader*[_max]; 275 _table = new ImageFileReader*[_max];
276 assert( _table != NULL && "allocation failed");
274 } 277 }
275 278
276 ImageFileReaderTable::~ImageFileReaderTable() { 279 ImageFileReaderTable::~ImageFileReaderTable() {
277 delete[] _table; 280 delete[] _table;
278 } 281 }
328 // Search for an exist image file. 331 // Search for an exist image file.
329 for (u4 i = 0; i < _reader_table.count(); i++) { 332 for (u4 i = 0; i < _reader_table.count(); i++) {
330 // Retrieve table entry. 333 // Retrieve table entry.
331 ImageFileReader* reader = _reader_table.get(i); 334 ImageFileReader* reader = _reader_table.get(i);
332 // If name matches, then reuse (bump up use count.) 335 // If name matches, then reuse (bump up use count.)
336 assert(reader->name() != NULL && "reader->name must not be null");
333 if (strcmp(reader->name(), name) == 0) { 337 if (strcmp(reader->name(), name) == 0) {
334 reader->inc_use(); 338 reader->inc_use();
335 return reader; 339 return reader;
336 } 340 }
337 } 341 }
338 } // Unlock the mutex 342 } // Unlock the mutex
339 343
340 // Need a new image reader. 344 // Need a new image reader.
341 ImageFileReader* reader = new ImageFileReader(name, big_endian); 345 ImageFileReader* reader = new ImageFileReader(name, big_endian);
342 bool opened = reader->open(); 346 if (reader == NULL || !reader->open()) {
343 // If failed to open. 347 // Failed to open.
344 if (!opened) {
345 delete reader; 348 delete reader;
346 return NULL; 349 return NULL;
347 } 350 }
348 351
349 // Lock to update 352 // Lock to update
350 SimpleCriticalSectionLock cs(&_reader_table_lock); 353 SimpleCriticalSectionLock cs(&_reader_table_lock);
351 // Search for an exist image file. 354 // Search for an existing image file.
352 for (u4 i = 0; i < _reader_table.count(); i++) { 355 for (u4 i = 0; i < _reader_table.count(); i++) {
353 // Retrieve table entry. 356 // Retrieve table entry.
354 ImageFileReader* existing_reader = _reader_table.get(i); 357 ImageFileReader* existing_reader = _reader_table.get(i);
355 // If name matches, then reuse (bump up use count.) 358 // If name matches, then reuse (bump up use count.)
359 assert(reader->name() != NULL && "reader->name still must not be null");
356 if (strcmp(existing_reader->name(), name) == 0) { 360 if (strcmp(existing_reader->name(), name) == 0) {
357 existing_reader->inc_use(); 361 existing_reader->inc_use();
358 reader->close(); 362 reader->close();
359 delete reader; 363 delete reader;
360 return existing_reader; 364 return existing_reader;
399 // Constructor intializes to a closed state. 403 // Constructor intializes to a closed state.
400 ImageFileReader::ImageFileReader(const char* name, bool big_endian) { 404 ImageFileReader::ImageFileReader(const char* name, bool big_endian) {
401 // Copy the image file name. 405 // Copy the image file name.
402 int len = (int) strlen(name) + 1; 406 int len = (int) strlen(name) + 1;
403 _name = new char[len]; 407 _name = new char[len];
408 assert(_name != NULL && "allocation failed");
404 strncpy(_name, name, len); 409 strncpy(_name, name, len);
405 // Initialize for a closed file. 410 // Initialize for a closed file.
406 _fd = -1; 411 _fd = -1;
407 _endian = Endian::get_handler(big_endian); 412 _endian = Endian::get_handler(big_endian);
408 _index_data = NULL; 413 _index_data = NULL;
471 _string_bytes = _index_data + string_bytes_offset; 476 _string_bytes = _index_data + string_bytes_offset;
472 477
473 // Initialize the module data 478 // Initialize the module data
474 ImageModuleData::module_data_name(buffer, _name); 479 ImageModuleData::module_data_name(buffer, _name);
475 module_data = new ImageModuleData(this, buffer); 480 module_data = new ImageModuleData(this, buffer);
476 // Successful open. 481 // Successful open (if memory allocation succeeded).
477 return true; 482 return module_data != NULL;
478 } 483 }
479 484
480 // Close image file. 485 // Close image file.
481 void ImageFileReader::close() { 486 void ImageFileReader::close() {
482 // Deallocate the index. 487 // Deallocate the index.
653 u1* compressed_data; 658 u1* compressed_data;
654 // If not memory mapped read in bytes. 659 // If not memory mapped read in bytes.
655 if (!MemoryMapImage) { 660 if (!MemoryMapImage) {
656 // Allocate buffer for compression. 661 // Allocate buffer for compression.
657 compressed_data = new u1[(u4)compressed_size]; 662 compressed_data = new u1[(u4)compressed_size];
663 assert (compressed_data != NULL && "allocation failed");
658 // Read bytes from offset beyond the image index. 664 // Read bytes from offset beyond the image index.
659 bool is_read = read_at(compressed_data, compressed_size, _index_size + offset); 665 bool is_read = read_at(compressed_data, compressed_size, _index_size + offset);
660 assert(is_read && "error reading from image or short read"); 666 assert(is_read && "error reading from image or short read");
661 } else { 667 } else {
662 compressed_data = get_data_address() + offset; 668 compressed_data = get_data_address() + offset;