comparison src/share/vm/runtime/os.cpp @ 8802:eca90b8a06eb

7030610: runtime/6878713/Test6878713.sh fails Error. failed to clean up files after test 7123945: runtime/6878713/Test6878713.sh require about 2G of native memory, swaps and times out Summary: Add new diagnostic option -XX:MallocMaxTestWords=NNN and fix Test6878713.sh. Reviewed-by: dcubed, coleenp, dholmes, iklam
author rdurbin
date Tue, 19 Mar 2013 11:33:11 -0700
parents 9fae07c31641
children 81d1b58c078f
comparison
equal deleted inserted replaced
8756:686916dc0439 8802:eca90b8a06eb
1 /* 1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
77 julong os::num_mallocs = 0; // # of calls to malloc/realloc 77 julong os::num_mallocs = 0; // # of calls to malloc/realloc
78 julong os::alloc_bytes = 0; // # of bytes allocated 78 julong os::alloc_bytes = 0; // # of bytes allocated
79 julong os::num_frees = 0; // # of calls to free 79 julong os::num_frees = 0; // # of calls to free
80 julong os::free_bytes = 0; // # of bytes freed 80 julong os::free_bytes = 0; // # of bytes freed
81 #endif 81 #endif
82
83 static juint cur_malloc_words = 0; // current size for MallocMaxTestWords
82 84
83 void os_init_globals() { 85 void os_init_globals() {
84 // Called from init_globals(). 86 // Called from init_globals().
85 // See Threads::create_vm() in thread.cpp, and init.cpp. 87 // See Threads::create_vm() in thread.cpp, and init.cpp.
86 os::init_globals(); 88 os::init_globals();
568 } 570 }
569 } 571 }
570 } 572 }
571 #endif 573 #endif
572 574
575 //
576 // This function supports testing of the malloc out of memory
577 // condition without really running the system out of memory.
578 //
579 static u_char* testMalloc(size_t alloc_size) {
580
581 if (MallocMaxTestWords > 0 &&
582 (cur_malloc_words + (alloc_size / BytesPerWord)) > MallocMaxTestWords) {
583 return NULL;
584 }
585
586 u_char* ptr = (u_char*)::malloc(alloc_size);
587
588 if (MallocMaxTestWords > 0 && (ptr != NULL)) {
589 Atomic::add(((jint) (alloc_size / BytesPerWord)),
590 (volatile jint *) &cur_malloc_words);
591 }
592 return ptr;
593 }
594
573 void* os::malloc(size_t size, MEMFLAGS memflags, address caller) { 595 void* os::malloc(size_t size, MEMFLAGS memflags, address caller) {
574 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1)); 596 NOT_PRODUCT(inc_stat_counter(&num_mallocs, 1));
575 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size)); 597 NOT_PRODUCT(inc_stat_counter(&alloc_bytes, size));
576 598
577 if (size == 0) { 599 if (size == 0) {
578 // return a valid pointer if size is zero 600 // return a valid pointer if size is zero
579 // if NULL is returned the calling functions assume out of memory. 601 // if NULL is returned the calling functions assume out of memory.
580 size = 1; 602 size = 1;
581 } 603 }
582 if (size > size + space_before + space_after) { // Check for rollover. 604
605 const size_t alloc_size = size + space_before + space_after;
606
607 if (size > alloc_size) { // Check for rollover.
583 return NULL; 608 return NULL;
584 } 609 }
610
585 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap()); 611 NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap());
586 u_char* ptr = (u_char*)::malloc(size + space_before + space_after); 612
613 u_char* ptr;
614
615 if (MallocMaxTestWords > 0) {
616 ptr = testMalloc(alloc_size);
617 } else {
618 ptr = (u_char*)::malloc(alloc_size);
619 }
587 620
588 #ifdef ASSERT 621 #ifdef ASSERT
589 if (ptr == NULL) return NULL; 622 if (ptr == NULL) return NULL;
590 if (MallocCushion) { 623 if (MallocCushion) {
591 for (u_char* p = ptr; p < ptr + MallocCushion; p++) *p = (u_char)badResourceValue; 624 for (u_char* p = ptr; p < ptr + MallocCushion; p++) *p = (u_char)badResourceValue;