hotspot/src/share/vm/runtime/os.cpp
changeset 33148 68fa8b6c4340
parent 33105 294e48b4f704
child 33593 60764a78fa5c
equal deleted inserted replaced
33146:77349b58b4c0 33148:68fa8b6c4340
    59 #include "utilities/defaultStream.hpp"
    59 #include "utilities/defaultStream.hpp"
    60 #include "utilities/events.hpp"
    60 #include "utilities/events.hpp"
    61 
    61 
    62 # include <signal.h>
    62 # include <signal.h>
    63 
    63 
    64 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
       
    65 
       
    66 OSThread*         os::_starting_thread    = NULL;
    64 OSThread*         os::_starting_thread    = NULL;
    67 address           os::_polling_page       = NULL;
    65 address           os::_polling_page       = NULL;
    68 volatile int32_t* os::_mem_serialize_page = NULL;
    66 volatile int32_t* os::_mem_serialize_page = NULL;
    69 uintptr_t         os::_serialize_page_mask = 0;
    67 uintptr_t         os::_serialize_page_mask = 0;
    70 long              os::_rand_seed          = 1;
    68 long              os::_rand_seed          = 1;
   619   // Wrap memory with guard
   617   // Wrap memory with guard
   620   GuardedMemory guarded(ptr, size + nmt_header_size);
   618   GuardedMemory guarded(ptr, size + nmt_header_size);
   621   ptr = guarded.get_user_ptr();
   619   ptr = guarded.get_user_ptr();
   622 #endif
   620 #endif
   623   if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
   621   if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
   624     tty->print_cr("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr);
   622     tty->print_cr("os::malloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
   625     breakpoint();
   623     breakpoint();
   626   }
   624   }
   627   debug_only(if (paranoid) verify_memory(ptr));
   625   debug_only(if (paranoid) verify_memory(ptr));
   628   if (PrintMalloc && tty != NULL) {
   626   if (PrintMalloc && tty != NULL) {
   629     tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr);
   627     tty->print_cr("os::malloc " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
   630   }
   628   }
   631 
   629 
   632   // we do not track guard memory
   630   // we do not track guard memory
   633   return MemTracker::record_malloc((address)ptr, size, memflags, stack, level);
   631   return MemTracker::record_malloc((address)ptr, size, memflags, stack, level);
   634 }
   632 }
   656 #else
   654 #else
   657   if (memblock == NULL) {
   655   if (memblock == NULL) {
   658     return os::malloc(size, memflags, stack);
   656     return os::malloc(size, memflags, stack);
   659   }
   657   }
   660   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
   658   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
   661     tty->print_cr("os::realloc caught " PTR_FORMAT, memblock);
   659     tty->print_cr("os::realloc caught " PTR_FORMAT, p2i(memblock));
   662     breakpoint();
   660     breakpoint();
   663   }
   661   }
   664   // NMT support
   662   // NMT support
   665   void* membase = MemTracker::malloc_base(memblock);
   663   void* membase = MemTracker::malloc_base(memblock);
   666   verify_memory(membase);
   664   verify_memory(membase);
   669     return NULL;
   667     return NULL;
   670   }
   668   }
   671   // always move the block
   669   // always move the block
   672   void* ptr = os::malloc(size, memflags, stack);
   670   void* ptr = os::malloc(size, memflags, stack);
   673   if (PrintMalloc && tty != NULL) {
   671   if (PrintMalloc && tty != NULL) {
   674     tty->print_cr("os::realloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, memblock, ptr);
   672     tty->print_cr("os::realloc " SIZE_FORMAT " bytes, " PTR_FORMAT " --> " PTR_FORMAT, size, p2i(memblock), p2i(ptr));
   675   }
   673   }
   676   // Copy to new memory if malloc didn't fail
   674   // Copy to new memory if malloc didn't fail
   677   if ( ptr != NULL ) {
   675   if ( ptr != NULL ) {
   678     GuardedMemory guarded(MemTracker::malloc_base(memblock));
   676     GuardedMemory guarded(MemTracker::malloc_base(memblock));
   679     // Guard's user data contains NMT header
   677     // Guard's user data contains NMT header
   680     size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock);
   678     size_t memblock_size = guarded.get_user_size() - MemTracker::malloc_header_size(memblock);
   681     memcpy(ptr, memblock, MIN2(size, memblock_size));
   679     memcpy(ptr, memblock, MIN2(size, memblock_size));
   682     if (paranoid) verify_memory(MemTracker::malloc_base(ptr));
   680     if (paranoid) verify_memory(MemTracker::malloc_base(ptr));
   683     if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
   681     if ((intptr_t)ptr == (intptr_t)MallocCatchPtr) {
   684       tty->print_cr("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, ptr);
   682       tty->print_cr("os::realloc caught, " SIZE_FORMAT " bytes --> " PTR_FORMAT, size, p2i(ptr));
   685       breakpoint();
   683       breakpoint();
   686     }
   684     }
   687     os::free(memblock);
   685     os::free(memblock);
   688   }
   686   }
   689   return ptr;
   687   return ptr;
   694 void  os::free(void *memblock) {
   692 void  os::free(void *memblock) {
   695   NOT_PRODUCT(inc_stat_counter(&num_frees, 1));
   693   NOT_PRODUCT(inc_stat_counter(&num_frees, 1));
   696 #ifdef ASSERT
   694 #ifdef ASSERT
   697   if (memblock == NULL) return;
   695   if (memblock == NULL) return;
   698   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
   696   if ((intptr_t)memblock == (intptr_t)MallocCatchPtr) {
   699     if (tty != NULL) tty->print_cr("os::free caught " PTR_FORMAT, memblock);
   697     if (tty != NULL) tty->print_cr("os::free caught " PTR_FORMAT, p2i(memblock));
   700     breakpoint();
   698     breakpoint();
   701   }
   699   }
   702   void* membase = MemTracker::record_free(memblock);
   700   void* membase = MemTracker::record_free(memblock);
   703   verify_memory(membase);
   701   verify_memory(membase);
   704   NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap());
   702   NOT_PRODUCT(if (MallocVerifyInterval > 0) check_heap());
   794     case 8: cols_per_line = 2;  break;
   792     case 8: cols_per_line = 2;  break;
   795     default: return;
   793     default: return;
   796   }
   794   }
   797 
   795 
   798   address p = start;
   796   address p = start;
   799   st->print(PTR_FORMAT ":   ", start);
   797   st->print(PTR_FORMAT ":   ", p2i(start));
   800   while (p < end) {
   798   while (p < end) {
   801     switch (unitsize) {
   799     switch (unitsize) {
   802       case 1: st->print("%02x", *(u1*)p); break;
   800       case 1: st->print("%02x", *(u1*)p); break;
   803       case 2: st->print("%04x", *(u2*)p); break;
   801       case 2: st->print("%04x", *(u2*)p); break;
   804       case 4: st->print("%08x", *(u4*)p); break;
   802       case 4: st->print("%08x", *(u4*)p); break;
   807     p += unitsize;
   805     p += unitsize;
   808     cols++;
   806     cols++;
   809     if (cols >= cols_per_line && p < end) {
   807     if (cols >= cols_per_line && p < end) {
   810        cols = 0;
   808        cols = 0;
   811        st->cr();
   809        st->cr();
   812        st->print(PTR_FORMAT ":   ", p);
   810        st->print(PTR_FORMAT ":   ", p2i(p));
   813     } else {
   811     } else {
   814        st->print(" ");
   812        st->print(" ");
   815     }
   813     }
   816   }
   814   }
   817   st->cr();
   815   st->cr();
   854   get_summary_cpu_info(buf, buflen);
   852   get_summary_cpu_info(buf, buflen);
   855   st->print("%s, ", buf);
   853   st->print("%s, ", buf);
   856   size_t mem = physical_memory()/G;
   854   size_t mem = physical_memory()/G;
   857   if (mem == 0) {  // for low memory systems
   855   if (mem == 0) {  // for low memory systems
   858     mem = physical_memory()/M;
   856     mem = physical_memory()/M;
   859     st->print("%d cores, %dM, ", processor_count(), mem);
   857     st->print("%d cores, " SIZE_FORMAT "M, ", processor_count(), mem);
   860   } else {
   858   } else {
   861     st->print("%d cores, %dG, ", processor_count(), mem);
   859     st->print("%d cores, " SIZE_FORMAT "G, ", processor_count(), mem);
   862   }
   860   }
   863   get_summary_os_info(buf, buflen);
   861   get_summary_os_info(buf, buflen);
   864   st->print_raw(buf);
   862   st->print_raw(buf);
   865   st->cr();
   863   st->cr();
   866 }
   864 }
   912   if (b != NULL) {
   910   if (b != NULL) {
   913     if (b->is_buffer_blob()) {
   911     if (b->is_buffer_blob()) {
   914       // the interpreter is generated into a buffer blob
   912       // the interpreter is generated into a buffer blob
   915       InterpreterCodelet* i = Interpreter::codelet_containing(addr);
   913       InterpreterCodelet* i = Interpreter::codelet_containing(addr);
   916       if (i != NULL) {
   914       if (i != NULL) {
   917         st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", addr, (int)(addr - i->code_begin()));
   915         st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", p2i(addr), (int)(addr - i->code_begin()));
   918         i->print_on(st);
   916         i->print_on(st);
   919         return;
   917         return;
   920       }
   918       }
   921       if (Interpreter::contains(addr)) {
   919       if (Interpreter::contains(addr)) {
   922         st->print_cr(INTPTR_FORMAT " is pointing into interpreter code"
   920         st->print_cr(INTPTR_FORMAT " is pointing into interpreter code"
   923                      " (not bytecode specific)", addr);
   921                      " (not bytecode specific)", p2i(addr));
   924         return;
   922         return;
   925       }
   923       }
   926       //
   924       //
   927       if (AdapterHandlerLibrary::contains(b)) {
   925       if (AdapterHandlerLibrary::contains(b)) {
   928         st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an AdapterHandler", addr, (int)(addr - b->code_begin()));
   926         st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an AdapterHandler", p2i(addr), (int)(addr - b->code_begin()));
   929         AdapterHandlerLibrary::print_handler_on(st, b);
   927         AdapterHandlerLibrary::print_handler_on(st, b);
   930       }
   928       }
   931       // the stubroutines are generated into a buffer blob
   929       // the stubroutines are generated into a buffer blob
   932       StubCodeDesc* d = StubCodeDesc::desc_for(addr);
   930       StubCodeDesc* d = StubCodeDesc::desc_for(addr);
   933       if (d != NULL) {
   931       if (d != NULL) {
   934         st->print_cr(INTPTR_FORMAT " is at begin+%d in a stub", addr, (int)(addr - d->begin()));
   932         st->print_cr(INTPTR_FORMAT " is at begin+%d in a stub", p2i(addr), (int)(addr - d->begin()));
   935         d->print_on(st);
   933         d->print_on(st);
   936         st->cr();
   934         st->cr();
   937         return;
   935         return;
   938       }
   936       }
   939       if (StubRoutines::contains(addr)) {
   937       if (StubRoutines::contains(addr)) {
   940         st->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) "
   938         st->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) stub routine", p2i(addr));
   941                      "stub routine", addr);
       
   942         return;
   939         return;
   943       }
   940       }
   944       // the InlineCacheBuffer is using stubs generated into a buffer blob
   941       // the InlineCacheBuffer is using stubs generated into a buffer blob
   945       if (InlineCacheBuffer::contains(addr)) {
   942       if (InlineCacheBuffer::contains(addr)) {
   946         st->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", addr);
   943         st->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", p2i(addr));
   947         return;
   944         return;
   948       }
   945       }
   949       VtableStub* v = VtableStubs::stub_containing(addr);
   946       VtableStub* v = VtableStubs::stub_containing(addr);
   950       if (v != NULL) {
   947       if (v != NULL) {
   951         st->print_cr(INTPTR_FORMAT " is at entry_point+%d in a vtable stub", addr, (int)(addr - v->entry_point()));
   948         st->print_cr(INTPTR_FORMAT " is at entry_point+%d in a vtable stub", p2i(addr), (int)(addr - v->entry_point()));
   952         v->print_on(st);
   949         v->print_on(st);
   953         st->cr();
   950         st->cr();
   954         return;
   951         return;
   955       }
   952       }
   956     }
   953     }
   957     nmethod* nm = b->as_nmethod_or_null();
   954     nmethod* nm = b->as_nmethod_or_null();
   958     if (nm != NULL) {
   955     if (nm != NULL) {
   959       ResourceMark rm;
   956       ResourceMark rm;
   960       st->print(INTPTR_FORMAT " is at entry_point+%d in (nmethod*)" INTPTR_FORMAT,
   957       st->print(INTPTR_FORMAT " is at entry_point+%d in (nmethod*)" INTPTR_FORMAT,
   961                 addr, (int)(addr - nm->entry_point()), nm);
   958                 p2i(addr), (int)(addr - nm->entry_point()), p2i(nm));
   962       if (verbose) {
   959       if (verbose) {
   963         st->print(" for ");
   960         st->print(" for ");
   964         nm->method()->print_value_on(st);
   961         nm->method()->print_value_on(st);
   965       }
   962       }
   966       st->cr();
   963       st->cr();
   967       nm->print_nmethod(verbose);
   964       nm->print_nmethod(verbose);
   968       return;
   965       return;
   969     }
   966     }
   970     st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", addr, (int)(addr - b->code_begin()));
   967     st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", p2i(addr), (int)(addr - b->code_begin()));
   971     b->print_on(st);
   968     b->print_on(st);
   972     return;
   969     return;
   973   }
   970   }
   974 
   971 
   975   if (Universe::heap()->is_in(addr)) {
   972   if (Universe::heap()->is_in(addr)) {
   983       p = (HeapWord*) addr;
   980       p = (HeapWord*) addr;
   984       print = true;
   981       print = true;
   985     }
   982     }
   986     if (print) {
   983     if (print) {
   987       if (p == (HeapWord*) addr) {
   984       if (p == (HeapWord*) addr) {
   988         st->print_cr(INTPTR_FORMAT " is an oop", addr);
   985         st->print_cr(INTPTR_FORMAT " is an oop", p2i(addr));
   989       } else {
   986       } else {
   990         st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, addr, p);
   987         st->print_cr(INTPTR_FORMAT " is pointing into object: " INTPTR_FORMAT, p2i(addr), p2i(p));
   991       }
   988       }
   992       oop(p)->print_on(st);
   989       oop(p)->print_on(st);
   993       return;
   990       return;
   994     }
   991     }
   995   } else {
   992   } else {
   996     if (Universe::heap()->is_in_reserved(addr)) {
   993     if (Universe::heap()->is_in_reserved(addr)) {
   997       st->print_cr(INTPTR_FORMAT " is an unallocated location "
   994       st->print_cr(INTPTR_FORMAT " is an unallocated location "
   998                    "in the heap", addr);
   995                    "in the heap", p2i(addr));
   999       return;
   996       return;
  1000     }
   997     }
  1001   }
   998   }
  1002   if (JNIHandles::is_global_handle((jobject) addr)) {
   999   if (JNIHandles::is_global_handle((jobject) addr)) {
  1003     st->print_cr(INTPTR_FORMAT " is a global jni handle", addr);
  1000     st->print_cr(INTPTR_FORMAT " is a global jni handle", p2i(addr));
  1004     return;
  1001     return;
  1005   }
  1002   }
  1006   if (JNIHandles::is_weak_global_handle((jobject) addr)) {
  1003   if (JNIHandles::is_weak_global_handle((jobject) addr)) {
  1007     st->print_cr(INTPTR_FORMAT " is a weak global jni handle", addr);
  1004     st->print_cr(INTPTR_FORMAT " is a weak global jni handle", p2i(addr));
  1008     return;
  1005     return;
  1009   }
  1006   }
  1010 #ifndef PRODUCT
  1007 #ifndef PRODUCT
  1011   // we don't keep the block list in product mode
  1008   // we don't keep the block list in product mode
  1012   if (JNIHandleBlock::any_contains((jobject) addr)) {
  1009   if (JNIHandleBlock::any_contains((jobject) addr)) {
  1013     st->print_cr(INTPTR_FORMAT " is a local jni handle", addr);
  1010     st->print_cr(INTPTR_FORMAT " is a local jni handle", p2i(addr));
  1014     return;
  1011     return;
  1015   }
  1012   }
  1016 #endif
  1013 #endif
  1017 
  1014 
  1018   for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
  1015   for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
  1019     // Check for privilege stack
  1016     // Check for privilege stack
  1020     if (thread->privileged_stack_top() != NULL &&
  1017     if (thread->privileged_stack_top() != NULL &&
  1021         thread->privileged_stack_top()->contains(addr)) {
  1018         thread->privileged_stack_top()->contains(addr)) {
  1022       st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
  1019       st->print_cr(INTPTR_FORMAT " is pointing into the privilege stack "
  1023                    "for thread: " INTPTR_FORMAT, addr, thread);
  1020                    "for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread));
  1024       if (verbose) thread->print_on(st);
  1021       if (verbose) thread->print_on(st);
  1025       return;
  1022       return;
  1026     }
  1023     }
  1027     // If the addr is a java thread print information about that.
  1024     // If the addr is a java thread print information about that.
  1028     if (addr == (address)thread) {
  1025     if (addr == (address)thread) {
  1029       if (verbose) {
  1026       if (verbose) {
  1030         thread->print_on(st);
  1027         thread->print_on(st);
  1031       } else {
  1028       } else {
  1032         st->print_cr(INTPTR_FORMAT " is a thread", addr);
  1029         st->print_cr(INTPTR_FORMAT " is a thread", p2i(addr));
  1033       }
  1030       }
  1034       return;
  1031       return;
  1035     }
  1032     }
  1036     // If the addr is in the stack region for this thread then report that
  1033     // If the addr is in the stack region for this thread then report that
  1037     // and print thread info
  1034     // and print thread info
  1038     if (thread->stack_base() >= addr &&
  1035     if (thread->stack_base() >= addr &&
  1039         addr > (thread->stack_base() - thread->stack_size())) {
  1036         addr > (thread->stack_base() - thread->stack_size())) {
  1040       st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
  1037       st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
  1041                    INTPTR_FORMAT, addr, thread);
  1038                    INTPTR_FORMAT, p2i(addr), p2i(thread));
  1042       if (verbose) thread->print_on(st);
  1039       if (verbose) thread->print_on(st);
  1043       return;
  1040       return;
  1044     }
  1041     }
  1045 
  1042 
  1046   }
  1043   }
  1050     if (Method::has_method_vptr((const void*)addr)) {
  1047     if (Method::has_method_vptr((const void*)addr)) {
  1051       ((Method*)addr)->print_value_on(st);
  1048       ((Method*)addr)->print_value_on(st);
  1052       st->cr();
  1049       st->cr();
  1053     } else {
  1050     } else {
  1054       // Use addr->print() from the debugger instead (not here)
  1051       // Use addr->print() from the debugger instead (not here)
  1055       st->print_cr(INTPTR_FORMAT " is pointing into metadata", addr);
  1052       st->print_cr(INTPTR_FORMAT " is pointing into metadata", p2i(addr));
  1056     }
  1053     }
  1057     return;
  1054     return;
  1058   }
  1055   }
  1059 
  1056 
  1060   // Try an OS specific find
  1057   // Try an OS specific find
  1061   if (os::find(addr, st)) {
  1058   if (os::find(addr, st)) {
  1062     return;
  1059     return;
  1063   }
  1060   }
  1064 
  1061 
  1065   st->print_cr(INTPTR_FORMAT " is an unknown value", addr);
  1062   st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
  1066 }
  1063 }
  1067 
  1064 
  1068 // Looks like all platforms except IA64 can use the same function to check
  1065 // Looks like all platforms except IA64 can use the same function to check
  1069 // if C stack is walkable beyond current frame. The check for fp() is not
  1066 // if C stack is walkable beyond current frame. The check for fp() is not
  1070 // necessary on Sparc, but it's harmless.
  1067 // necessary on Sparc, but it's harmless.
  1459   if (TracePageSizes) {
  1456   if (TracePageSizes) {
  1460     tty->print_cr("%s:  min=" SIZE_FORMAT " max=" SIZE_FORMAT
  1457     tty->print_cr("%s:  min=" SIZE_FORMAT " max=" SIZE_FORMAT
  1461                   " pg_sz=" SIZE_FORMAT " base=" PTR_FORMAT
  1458                   " pg_sz=" SIZE_FORMAT " base=" PTR_FORMAT
  1462                   " size=" SIZE_FORMAT,
  1459                   " size=" SIZE_FORMAT,
  1463                   str, region_min_size, region_max_size,
  1460                   str, region_min_size, region_max_size,
  1464                   page_size, base, size);
  1461                   page_size, p2i(base), size);
  1465   }
  1462   }
  1466 }
  1463 }
  1467 #endif  // #ifndef PRODUCT
  1464 #endif  // #ifndef PRODUCT
  1468 
  1465 
  1469 // This is the working definition of a server class machine:
  1466 // This is the working definition of a server class machine: