Print this page
rev 6886 : 8058251: assert(_count > 0) failed: Negative counter when running runtime/NMT/MallocTrackingVerify.java
Summary: Fixed an issue when overflowing the MallocSite hash table bucket
Reviewed-by: coleenp, gtriantafill

Split Split Close
Expand all
Collapse all
          --- old/hotspot/src/share/vm/prims/whitebox.cpp
          +++ new/hotspot/src/share/vm/prims/whitebox.cpp
↓ open down ↓ 292 lines elided ↑ open up ↑
 293  293  WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
 294  294    return (jint)HeapRegion::GrainBytes;
 295  295  WB_END
 296  296  #endif // INCLUDE_ALL_GCS
 297  297  
 298  298  #if INCLUDE_NMT
 299  299  // Alloc memory using the test memory type so that we can use that to see if
 300  300  // NMT picks it up correctly
 301  301  WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
 302  302    jlong addr = 0;
 303      -    addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
      303 +  addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
 304  304    return addr;
 305  305  WB_END
 306  306  
 307  307  // Alloc memory with pseudo call stack. The test can create psudo malloc
 308  308  // allocation site to stress the malloc tracking.
 309  309  WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
 310  310    address pc = (address)(size_t)pseudo_stack;
 311  311    NativeCallStack stack(&pc, 1);
 312      -  return (jlong)os::malloc(size, mtTest, stack);
      312 +  return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
 313  313  WB_END
 314  314  
 315  315  // Free the memory allocated by NMTAllocTest
 316  316  WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
 317  317    os::free((void*)(uintptr_t)mem, mtTest);
 318  318  WB_END
 319  319  
 320  320  WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
 321  321    jlong addr = 0;
 322  322  
↓ open down ↓ 14 lines elided ↑ open up ↑
 337  337  WB_END
 338  338  
 339  339  WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 340  340    os::release_memory((char *)(uintptr_t)addr, size);
 341  341  WB_END
 342  342  
 343  343  WB_ENTRY(jboolean, WB_NMTIsDetailSupported(JNIEnv* env))
 344  344    return MemTracker::tracking_level() == NMT_detail;
 345  345  WB_END
 346  346  
 347      -WB_ENTRY(void, WB_NMTOverflowHashBucket(JNIEnv* env, jobject o, jlong num))
 348      -  address pc = (address)1;
 349      -  for (jlong index = 0; index < num; index ++) {
 350      -    NativeCallStack stack(&pc, 1);
 351      -    os::malloc(0, mtTest, stack);
 352      -    pc += MallocSiteTable::hash_buckets();
 353      -  }
 354      -WB_END
 355      -
 356  347  WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
 357  348    // Test that we can downgrade NMT levels but not upgrade them.
 358  349    if (MemTracker::tracking_level() == NMT_off) {
 359  350      MemTracker::transition_to(NMT_off);
 360  351      return MemTracker::tracking_level() == NMT_off;
 361  352    } else {
 362  353      assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
 363  354      MemTracker::transition_to(NMT_summary);
 364  355      assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
 365  356  
↓ open down ↓ 10 lines elided ↑ open up ↑
 376  367      // table overflows in another thread, it tries to change the code to summary.
 377  368      MemTracker::transition_to(NMT_summary);
 378  369      assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 379  370  
 380  371      // Really can never go up to detail, verify that the code would never do this.
 381  372      MemTracker::transition_to(NMT_detail);
 382  373      assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 383  374      return MemTracker::tracking_level() == NMT_minimal;
 384  375    }
 385  376  WB_END
      377 +
      378 +WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
      379 +  int hash_size = MallocSiteTable::hash_buckets();
      380 +  assert(hash_size > 0, "NMT hash_size should be > 0");
      381 +  return (jint)hash_size;
      382 +WB_END
 386  383  #endif // INCLUDE_NMT
 387  384  
 388  385  static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
 389  386    assert(method != NULL, "method should not be null");
 390  387    ThreadToNativeFromVM ttn(thread);
 391  388    return env->FromReflectedMethod(method);
 392  389  }
 393  390  
 394  391  WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
 395  392    MutexLockerEx mu(Compile_lock);
↓ open down ↓ 578 lines elided ↑ open up ↑
 974  971    {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
 975  972  #endif // INCLUDE_ALL_GCS
 976  973  #if INCLUDE_NMT
 977  974    {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
 978  975    {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
 979  976    {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
 980  977    {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
 981  978    {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
 982  979    {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
 983  980    {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
 984      -  {CC"NMTOverflowHashBucket", CC"(J)V",               (void*)&WB_NMTOverflowHashBucket},
 985  981    {CC"NMTIsDetailSupported",CC"()Z",                  (void*)&WB_NMTIsDetailSupported},
 986  982    {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
      983 +  {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
 987  984  #endif // INCLUDE_NMT
 988  985    {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
 989  986    {CC"deoptimizeMethod",   CC"(Ljava/lang/reflect/Executable;Z)I",
 990  987                                                        (void*)&WB_DeoptimizeMethod  },
 991  988    {CC"isMethodCompiled",   CC"(Ljava/lang/reflect/Executable;Z)Z",
 992  989                                                        (void*)&WB_IsMethodCompiled  },
 993  990    {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z",
 994  991                                                        (void*)&WB_IsMethodCompilable},
 995  992    {CC"isMethodQueuedForCompilation",
 996  993        CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
↓ open down ↓ 66 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX