1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2019, 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. |
21 * questions. |
21 * questions. |
22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "runtime/safepointVerifiers.hpp" |
|
27 #include "gc/shared/collectedHeap.hpp" |
26 #include "gc/shared/collectedHeap.hpp" |
28 #include "memory/universe.hpp" |
27 #include "memory/universe.hpp" |
|
28 #include "runtime/safepoint.hpp" |
|
29 #include "runtime/safepointVerifiers.hpp" |
29 #include "utilities/debug.hpp" |
30 #include "utilities/debug.hpp" |
30 |
|
31 // Implementation of NoGCVerifier |
|
32 |
31 |
33 #ifdef ASSERT |
32 #ifdef ASSERT |
34 |
33 |
35 NoGCVerifier::NoGCVerifier(bool verifygc) { |
34 NoSafepointVerifier::NoSafepointVerifier() : _thread(Thread::current()) { |
36 _verifygc = verifygc; |
35 _thread->_no_safepoint_count++; |
37 if (_verifygc) { |
|
38 CollectedHeap* h = Universe::heap(); |
|
39 assert(!h->is_gc_active(), "GC active during NoGCVerifier"); |
|
40 _old_invocations = h->total_collections(); |
|
41 } |
|
42 } |
36 } |
43 |
37 |
44 |
38 NoSafepointVerifier::~NoSafepointVerifier() { |
45 NoGCVerifier::~NoGCVerifier() { |
39 _thread->_no_safepoint_count--; |
46 if (_verifygc) { |
|
47 CollectedHeap* h = Universe::heap(); |
|
48 assert(!h->is_gc_active(), "GC active during NoGCVerifier"); |
|
49 if (_old_invocations != h->total_collections()) { |
|
50 fatal("collection in a NoGCVerifier secured function"); |
|
51 } |
|
52 } |
|
53 } |
40 } |
54 |
41 |
55 PauseNoGCVerifier::PauseNoGCVerifier(NoGCVerifier * ngcv) { |
42 PauseNoSafepointVerifier::PauseNoSafepointVerifier(NoSafepointVerifier* nsv) |
56 _ngcv = ngcv; |
43 : _nsv(nsv) { |
57 if (_ngcv->_verifygc) { |
44 assert(_nsv->_thread == Thread::current(), "must be"); |
58 // if we were verifying, then make sure that nothing is |
45 _nsv->_thread->_no_safepoint_count--; |
59 // wrong before we "pause" verification |
|
60 CollectedHeap* h = Universe::heap(); |
|
61 assert(!h->is_gc_active(), "GC active during NoGCVerifier"); |
|
62 if (_ngcv->_old_invocations != h->total_collections()) { |
|
63 fatal("collection in a NoGCVerifier secured function"); |
|
64 } |
|
65 } |
|
66 } |
46 } |
67 |
47 |
68 |
48 PauseNoSafepointVerifier::~PauseNoSafepointVerifier() { |
69 PauseNoGCVerifier::~PauseNoGCVerifier() { |
49 _nsv->_thread->_no_safepoint_count++; |
70 if (_ngcv->_verifygc) { |
|
71 // if we were verifying before, then reenable verification |
|
72 CollectedHeap* h = Universe::heap(); |
|
73 assert(!h->is_gc_active(), "GC active during NoGCVerifier"); |
|
74 _ngcv->_old_invocations = h->total_collections(); |
|
75 } |
|
76 } |
50 } |
77 |
51 #endif // ASSERT |
78 #endif |
|