Mercurial > hg > graal-compiler
comparison src/share/vm/memory/filemap.cpp @ 20527:8cb56c8cb30d
Merge
author | jiangli |
---|---|
date | Mon, 15 Sep 2014 16:39:00 -0400 |
parents | 6e0cb14ce59b ca6d25be853b |
children | 0558eb13dcf3 |
comparison
equal
deleted
inserted
replaced
20411:fe1f65b0a2d8 | 20527:8cb56c8cb30d |
---|---|
312 } | 312 } |
313 if (_header->_version != current_version()) { | 313 if (_header->_version != current_version()) { |
314 fail_continue("The shared archive file has the wrong version."); | 314 fail_continue("The shared archive file has the wrong version."); |
315 return false; | 315 return false; |
316 } | 316 } |
317 _file_offset = (long)n; | |
318 | 317 |
319 size_t info_size = _header->_paths_misc_info_size; | 318 size_t info_size = _header->_paths_misc_info_size; |
320 _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass); | 319 _paths_misc_info = NEW_C_HEAP_ARRAY_RETURN_NULL(char, info_size, mtClass); |
321 if (_paths_misc_info == NULL) { | 320 if (_paths_misc_info == NULL) { |
322 fail_continue("Unable to read the file header."); | 321 fail_continue("Unable to read the file header."); |
325 n = os::read(fd, _paths_misc_info, (unsigned int)info_size); | 324 n = os::read(fd, _paths_misc_info, (unsigned int)info_size); |
326 if (n != info_size) { | 325 if (n != info_size) { |
327 fail_continue("Unable to read the shared path info header."); | 326 fail_continue("Unable to read the shared path info header."); |
328 FREE_C_HEAP_ARRAY(char, _paths_misc_info, mtClass); | 327 FREE_C_HEAP_ARRAY(char, _paths_misc_info, mtClass); |
329 _paths_misc_info = NULL; | 328 _paths_misc_info = NULL; |
329 return false; | |
330 } | |
331 | |
332 size_t len = lseek(fd, 0, SEEK_END); | |
333 struct FileMapInfo::FileMapHeader::space_info* si = | |
334 &_header->_space[MetaspaceShared::mc]; | |
335 if (si->_file_offset >= len || len - si->_file_offset < si->_used) { | |
336 fail_continue("The shared archive file has been truncated."); | |
330 return false; | 337 return false; |
331 } | 338 } |
332 | 339 |
333 _file_offset += (long)n; | 340 _file_offset += (long)n; |
334 return true; | 341 return true; |
428 si->_base = base; | 435 si->_base = base; |
429 si->_used = size; | 436 si->_used = size; |
430 si->_capacity = capacity; | 437 si->_capacity = capacity; |
431 si->_read_only = read_only; | 438 si->_read_only = read_only; |
432 si->_allow_exec = allow_exec; | 439 si->_allow_exec = allow_exec; |
440 si->_crc = ClassLoader::crc32(0, base, (jint)size); | |
433 write_bytes_aligned(base, (int)size); | 441 write_bytes_aligned(base, (int)size); |
434 } | 442 } |
435 | 443 |
436 | 444 |
437 // Dump bytes to file -- at the current file position. | 445 // Dump bytes to file -- at the current file position. |
452 | 460 |
453 | 461 |
454 // Align file position to an allocation unit boundary. | 462 // Align file position to an allocation unit boundary. |
455 | 463 |
456 void FileMapInfo::align_file_position() { | 464 void FileMapInfo::align_file_position() { |
457 long new_file_offset = align_size_up(_file_offset, os::vm_allocation_granularity()); | 465 size_t new_file_offset = align_size_up(_file_offset, |
466 os::vm_allocation_granularity()); | |
458 if (new_file_offset != _file_offset) { | 467 if (new_file_offset != _file_offset) { |
459 _file_offset = new_file_offset; | 468 _file_offset = new_file_offset; |
460 if (_file_open) { | 469 if (_file_open) { |
461 // Seek one byte back from the target and write a byte to insure | 470 // Seek one byte back from the target and write a byte to insure |
462 // that the written file is the correct length. | 471 // that the written file is the correct length. |
463 _file_offset -= 1; | 472 _file_offset -= 1; |
464 if (lseek(_fd, _file_offset, SEEK_SET) < 0) { | 473 if (lseek(_fd, (long)_file_offset, SEEK_SET) < 0) { |
465 fail_stop("Unable to seek.", NULL); | 474 fail_stop("Unable to seek.", NULL); |
466 } | 475 } |
467 char zero = 0; | 476 char zero = 0; |
468 write_bytes(&zero, 1); | 477 write_bytes(&zero, 1); |
469 } | 478 } |
566 MemTracker::record_virtual_memory_type((address)base, mtClassShared); | 575 MemTracker::record_virtual_memory_type((address)base, mtClassShared); |
567 #endif | 576 #endif |
568 return base; | 577 return base; |
569 } | 578 } |
570 | 579 |
580 bool FileMapInfo::verify_region_checksum(int i) { | |
581 if (!VerifySharedSpaces) { | |
582 return true; | |
583 } | |
584 const char* buf = _header->_space[i]._base; | |
585 size_t sz = _header->_space[i]._used; | |
586 int crc = ClassLoader::crc32(0, buf, (jint)sz); | |
587 if (crc != _header->_space[i]._crc) { | |
588 fail_continue("Checksum verification failed."); | |
589 return false; | |
590 } | |
591 return true; | |
592 } | |
571 | 593 |
572 // Unmap a memory region in the address space. | 594 // Unmap a memory region in the address space. |
573 | 595 |
574 void FileMapInfo::unmap_region(int i) { | 596 void FileMapInfo::unmap_region(int i) { |
575 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; | 597 struct FileMapInfo::FileMapHeader::space_info* si = &_header->_space[i]; |
626 SharedMiscDataSize = _header->_space[2]._capacity; | 648 SharedMiscDataSize = _header->_space[2]._capacity; |
627 SharedMiscCodeSize = _header->_space[3]._capacity; | 649 SharedMiscCodeSize = _header->_space[3]._capacity; |
628 return true; | 650 return true; |
629 } | 651 } |
630 | 652 |
653 int FileMapInfo::FileMapHeader::compute_crc() { | |
654 char* header = data(); | |
655 // start computing from the field after _crc | |
656 char* buf = (char*)&_crc + sizeof(int); | |
657 size_t sz = data_size() - (buf - header); | |
658 int crc = ClassLoader::crc32(0, buf, (jint)sz); | |
659 return crc; | |
660 } | |
661 | |
662 int FileMapInfo::compute_header_crc() { | |
663 return _header->compute_crc(); | |
664 } | |
665 | |
631 bool FileMapInfo::FileMapHeader::validate() { | 666 bool FileMapInfo::FileMapHeader::validate() { |
667 if (_magic != (int)0xf00baba2) { | |
668 FileMapInfo::fail_continue("The shared archive file has a bad magic number."); | |
669 return false; | |
670 } | |
671 if (VerifySharedSpaces && compute_crc() != _crc) { | |
672 fail_continue("Header checksum verification failed."); | |
673 return false; | |
674 } | |
632 if (_version != current_version()) { | 675 if (_version != current_version()) { |
633 FileMapInfo::fail_continue("The shared archive file is the wrong version."); | 676 FileMapInfo::fail_continue("The shared archive file is the wrong version."); |
634 return false; | 677 |
635 } | |
636 if (_magic != (int)0xf00baba2) { | |
637 FileMapInfo::fail_continue("The shared archive file has a bad magic number."); | |
638 return false; | 678 return false; |
639 } | 679 } |
640 char header_version[JVM_IDENT_MAX]; | 680 char header_version[JVM_IDENT_MAX]; |
641 get_header_version(header_version); | 681 get_header_version(header_version); |
642 if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { | 682 if (strncmp(_jvm_ident, header_version, JVM_IDENT_MAX-1) != 0) { |