src/share/vm/memory/gcLocker.inline.hpp

changeset 3494
1a2723f7ad8e
parent 2314
f95d63e2154a
child 3576
ad3b47344802
     1.1 --- a/src/share/vm/memory/gcLocker.inline.hpp	Thu Jan 26 19:39:08 2012 -0800
     1.2 +++ b/src/share/vm/memory/gcLocker.inline.hpp	Sun Jan 29 16:46:04 2012 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -28,16 +28,11 @@
    1.11  #include "memory/gcLocker.hpp"
    1.12  
    1.13  inline bool GC_locker::is_active() {
    1.14 +  assert(_needs_gc || SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
    1.15 +  verify_critical_count();
    1.16    return _lock_count > 0 || _jni_lock_count > 0;
    1.17  }
    1.18  
    1.19 -inline bool GC_locker::check_active_before_gc() {
    1.20 -  if (is_active()) {
    1.21 -    set_needs_gc();
    1.22 -  }
    1.23 -  return is_active();
    1.24 -}
    1.25 -
    1.26  inline void GC_locker::lock() {
    1.27    // cast away volatile
    1.28    Atomic::inc(&_lock_count);
    1.29 @@ -56,24 +51,28 @@
    1.30  
    1.31  inline void GC_locker::lock_critical(JavaThread* thread) {
    1.32    if (!thread->in_critical()) {
    1.33 -    if (!needs_gc()) {
    1.34 -      jni_lock();
    1.35 -    } else {
    1.36 -      jni_lock_slow();
    1.37 +    if (needs_gc()) {
    1.38 +      // jni_lock call calls enter_critical under the lock so that the
    1.39 +      // global lock count and per thread count are in agreement.
    1.40 +      jni_lock(thread);
    1.41 +      return;
    1.42      }
    1.43 +    increment_debug_jni_lock_count();
    1.44    }
    1.45    thread->enter_critical();
    1.46  }
    1.47  
    1.48  inline void GC_locker::unlock_critical(JavaThread* thread) {
    1.49 +  if (thread->in_last_critical()) {
    1.50 +    if (needs_gc()) {
    1.51 +      // jni_unlock call calls exit_critical under the lock so that
    1.52 +      // the global lock count and per thread count are in agreement.
    1.53 +      jni_unlock(thread);
    1.54 +      return;
    1.55 +    }
    1.56 +    decrement_debug_jni_lock_count();
    1.57 +  }
    1.58    thread->exit_critical();
    1.59 -  if (!thread->in_critical()) {
    1.60 -    if (!needs_gc()) {
    1.61 -      jni_unlock();
    1.62 -    } else {
    1.63 -      jni_unlock_slow();
    1.64 -    }
    1.65 -  }
    1.66  }
    1.67  
    1.68  #endif // SHARE_VM_MEMORY_GCLOCKER_INLINE_HPP

mercurial