Wed, 09 Oct 2019 16:11:58 +0800
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
Reviewed-by: egahlin, rwestberg
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #ifndef SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP |
apetushkov@9858 | 26 | #define SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP |
apetushkov@9858 | 27 | |
apetushkov@9858 | 28 | #include "memory/allocation.hpp" |
apetushkov@9858 | 29 | #include "jfr/utilities/jfrTime.hpp" |
apetushkov@9858 | 30 | |
ddong@9885 | 31 | typedef u8 traceid; |
ddong@9885 | 32 | |
apetushkov@9858 | 33 | class BoolObjectClosure; |
ddong@9885 | 34 | class JfrStackTrace; |
apetushkov@9858 | 35 | class OopClosure; |
apetushkov@9858 | 36 | class ObjectSample; |
apetushkov@9858 | 37 | class ObjectSampler; |
apetushkov@9858 | 38 | class SampleList; |
apetushkov@9858 | 39 | class SamplePriorityQueue; |
apetushkov@9858 | 40 | class Thread; |
apetushkov@9858 | 41 | |
apetushkov@9858 | 42 | // Class reponsible for holding samples and |
apetushkov@9858 | 43 | // making sure the samples are evenly distributed as |
apetushkov@9858 | 44 | // new entries are added and removed. |
apetushkov@9858 | 45 | class ObjectSampler : public CHeapObj<mtTracing> { |
ddong@9885 | 46 | friend class EventEmitter; |
ddong@9885 | 47 | friend class JfrRecorderService; |
apetushkov@9858 | 48 | friend class LeakProfiler; |
apetushkov@9858 | 49 | friend class StartOperation; |
apetushkov@9858 | 50 | friend class StopOperation; |
ddong@9885 | 51 | friend class ObjectSampleCheckpoint; |
ddong@9885 | 52 | friend class WriteObjectSampleStacktrace; |
apetushkov@9858 | 53 | private: |
apetushkov@9858 | 54 | SamplePriorityQueue* _priority_queue; |
apetushkov@9858 | 55 | SampleList* _list; |
apetushkov@9858 | 56 | JfrTicks _last_sweep; |
apetushkov@9858 | 57 | size_t _total_allocated; |
apetushkov@9858 | 58 | size_t _threshold; |
apetushkov@9858 | 59 | size_t _size; |
apetushkov@9858 | 60 | bool _dead_samples; |
apetushkov@9858 | 61 | |
ddong@9885 | 62 | // Lifecycle |
apetushkov@9858 | 63 | explicit ObjectSampler(size_t size); |
apetushkov@9858 | 64 | ~ObjectSampler(); |
ddong@9885 | 65 | static bool create(size_t size); |
ddong@9885 | 66 | static bool is_created(); |
ddong@9885 | 67 | static ObjectSampler* sampler(); |
ddong@9885 | 68 | static void destroy(); |
apetushkov@9858 | 69 | |
ddong@9885 | 70 | // For operations that require exclusive access (non-safepoint) |
ddong@9885 | 71 | static ObjectSampler* acquire(); |
ddong@9885 | 72 | static void release(); |
ddong@9885 | 73 | |
ddong@9885 | 74 | // Stacktrace |
ddong@9885 | 75 | static void fill_stacktrace(JfrStackTrace* stacktrace, JavaThread* thread); |
ddong@9885 | 76 | traceid stacktrace_id(const JfrStackTrace* stacktrace, JavaThread* thread); |
ddong@9885 | 77 | |
ddong@9885 | 78 | // Sampling |
ddong@9885 | 79 | static void sample(HeapWord* object, size_t size, JavaThread* thread); |
ddong@9885 | 80 | void add(HeapWord* object, size_t size, traceid thread_id, JfrStackTrace* stacktrace, JavaThread* thread); |
ddong@9885 | 81 | void scavenge(); |
apetushkov@9858 | 82 | void remove_dead(ObjectSample* sample); |
apetushkov@9858 | 83 | |
apetushkov@9858 | 84 | // Called by GC |
ddong@9885 | 85 | static void oops_do(BoolObjectClosure* is_alive, OopClosure* f); |
apetushkov@9858 | 86 | |
apetushkov@9858 | 87 | const ObjectSample* item_at(int index) const; |
apetushkov@9858 | 88 | ObjectSample* item_at(int index); |
apetushkov@9858 | 89 | int item_count() const; |
egahlin@9867 | 90 | const ObjectSample* first() const; |
apetushkov@9858 | 91 | const ObjectSample* last() const; |
apetushkov@9858 | 92 | const ObjectSample* last_resolved() const; |
apetushkov@9858 | 93 | void set_last_resolved(const ObjectSample* sample); |
apetushkov@9858 | 94 | const JfrTicks& last_sweep() const; |
apetushkov@9858 | 95 | }; |
apetushkov@9858 | 96 | |
apetushkov@9858 | 97 | #endif // SHARE_VM_LEAKPROFILER_SAMPLING_OBJECTSAMPLER_HPP |