< prev index next >

src/share/vm/memory/filemap.cpp

Print this page


 452   } else {
 453     si->_addr._base = base;
 454   }
 455   si->_used = size;
 456   si->_read_only = read_only;
 457   si->_allow_exec = allow_exec;
 458   si->_crc = ClassLoader::crc32(0, base, (jint)size);
 459   write_bytes_aligned(base, (int)size);
 460 }
 461 
 462 // Write the string space. The string space contains one or multiple GC(G1) regions.
 463 // When the total string space size is smaller than one GC region of the dump time,
 464 // only one string region is used for shared strings.
 465 //
 466 // If the total string space size is bigger than one GC region, there would be more
 467 // than one GC regions allocated for shared strings. The first/bottom GC region might
 468 // be a partial GC region with the empty portion at the higher address within that region.
 469 // The non-empty portion of the first region is written into the archive as one string
 470 // region. The rest are consecutive full GC regions if they exist, which can be written
 471 // out in one chunk as another string region.
 472 void FileMapInfo::write_string_regions(GrowableArray<MemRegion> *regions) {
























 473   for (int i = MetaspaceShared::first_string;
 474            i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
 475     char* start = NULL;
 476     size_t size = 0;
 477     if (regions->is_nonempty()) {

 478       if (i == MetaspaceShared::first_string) {
 479         MemRegion first = regions->first();
 480         start = (char*)first.start();
 481         size = first.byte_size();




 482       } else {
 483         int len = regions->length();



 484         if (len > 1) {
 485           start = (char*)regions->at(1).start();
 486           size = (char*)regions->at(len - 1).end() - start;



 487         }
 488       }
 489     }


 490     write_region(i, start, size, false, false);
 491   }
 492 }
 493 
 494 
 495 // Dump bytes to file -- at the current file position.
 496 
 497 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
 498   if (_file_open) {
 499     int n = ::write(_fd, buffer, nbytes);
 500     if (n != nbytes) {
 501       // It is dangerous to leave the corrupted shared archive file around,
 502       // close and remove the file. See bug 6372906.
 503       close();
 504       remove(_full_path);
 505       fail_stop("Unable to write to shared archive file.");
 506     }
 507   }
 508   _file_offset += nbytes;
 509 }




 452   } else {
 453     si->_addr._base = base;
 454   }
 455   si->_used = size;
 456   si->_read_only = read_only;
 457   si->_allow_exec = allow_exec;
 458   si->_crc = ClassLoader::crc32(0, base, (jint)size);
 459   write_bytes_aligned(base, (int)size);
 460 }
 461 
 462 // Write the string space. The string space contains one or multiple GC(G1) regions.
 463 // When the total string space size is smaller than one GC region of the dump time,
 464 // only one string region is used for shared strings.
 465 //
 466 // If the total string space size is bigger than one GC region, there would be more
 467 // than one GC regions allocated for shared strings. The first/bottom GC region might
 468 // be a partial GC region with the empty portion at the higher address within that region.
 469 // The non-empty portion of the first region is written into the archive as one string
 470 // region. The rest are consecutive full GC regions if they exist, which can be written
 471 // out in one chunk as another string region.
 472 //
 473 // Here's the mapping from (GrowableArray<MemRegion> *regions) -> (metaspace string regions).
 474 //   + We have 1 or more heap regions: r0, r1, r2 ..... rn
 475 //   + We have 2 metaspace string regions: s0 and s1
 476 //
 477 // If there's a single heap region (r0), then s0 == r0, and s1 is empty.
 478 // Otherwise:
 479 //
 480 // "X" represented space that's occupied by heap objects.
 481 // "_" represented unused spaced in the heap region.
 482 //
 483 //
 484 //    |r0        | r1  | r2 | ...... | rn |
 485 //    |XXXXXX|__ |XXXXX|XXXX|XXXXXXXX|XXXX|
 486 //    |<-s0->|   |<- s1 ----------------->|
 487 //            ^^^
 488 //             |
 489 //             +-- unmapped space
 490 void FileMapInfo::write_string_regions(GrowableArray<MemRegion> *regions,
 491                                        char** st0_start, char** st0_top, char** st0_end,
 492                                        char** st1_start, char** st1_top, char** st1_end) {
 493   *st0_start = *st0_top = *st0_end = NULL;
 494   *st1_start = *st1_top = *st1_end = NULL;
 495 
 496   assert(MetaspaceShared::max_strings == 2, "this loop doesn't work for any other value");
 497   for (int i = MetaspaceShared::first_string;
 498            i < MetaspaceShared::first_string + MetaspaceShared::max_strings; i++) {
 499     char* start = NULL;
 500     size_t size = 0;
 501     int len = regions->length();
 502     if (len > 0) {
 503       if (i == MetaspaceShared::first_string) {
 504         MemRegion first = regions->first();
 505         start = (char*)first.start();
 506         size = first.byte_size();
 507         *st0_start = start;
 508         *st0_top = start + size;
 509         if (len > 1) {
 510           *st0_end = (char*)regions->at(1).start();
 511         } else {
 512           *st0_end = start + size;
 513         }
 514       } else {
 515         assert(i == MetaspaceShared::first_string + 1, "must be");
 516         if (len > 1) {
 517           start = (char*)regions->at(1).start();
 518           size = (char*)regions->at(len - 1).end() - start;
 519           *st1_start = start;
 520           *st1_top = start + size;
 521           *st1_end = start + size;
 522         }
 523       }
 524     }
 525     log_info(cds)("String region %d " INTPTR_FORMAT " - " INTPTR_FORMAT " = " SIZE_FORMAT_W(8) " bytes",
 526                   i, p2i(start), p2i(start + size), size);
 527     write_region(i, start, size, false, false);
 528   }
 529 }
 530 
 531 
 532 // Dump bytes to file -- at the current file position.
 533 
 534 void FileMapInfo::write_bytes(const void* buffer, int nbytes) {
 535   if (_file_open) {
 536     int n = ::write(_fd, buffer, nbytes);
 537     if (n != nbytes) {
 538       // It is dangerous to leave the corrupted shared archive file around,
 539       // close and remove the file. See bug 6372906.
 540       close();
 541       remove(_full_path);
 542       fail_stop("Unable to write to shared archive file.");
 543     }
 544   }
 545   _file_offset += nbytes;
 546 }


< prev index next >