Tue, 26 Nov 2013 14:35:38 +0100
8027675: Full collections with Serial slower in JDK 8 compared to 7u40
Summary: Reduced the number of calls to follow_class_loader and instead marked and pushed the klass holder directly. Also removed unneeded calls to adjust_klass.
Reviewed-by: coleenp, jmasa, mgerdin, tschatzl
1 /*
2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
28 #include "utilities/macros.hpp"
29 #if INCLUDE_ALL_GCS
30 #include "runtime/thread.hpp"
31 #endif // INCLUDE_ALL_GCS
33 class VoidClosure;
35 // A SuspendibleThreadSet is (obviously) a set of threads that can be
36 // suspended. A thread can join and later leave the set, and periodically
37 // yield. If some thread (not in the set) requests, via suspend_all, that
38 // the threads be suspended, then the requesting thread is blocked until
39 // all the threads in the set have yielded or left the set. (Threads may
40 // not enter the set when an attempted suspension is in progress.) The
41 // suspending thread later calls resume_all, allowing the suspended threads
42 // to continue.
44 class SuspendibleThreadSet {
45 Monitor* _m;
46 int _async;
47 bool _async_stop;
48 int _async_stopped;
49 bool _initialized;
50 double _suspend_all_start;
52 void initialize_work();
54 public:
55 SuspendibleThreadSet() : _initialized(false) {}
57 // Add the current thread to the set. May block if a suspension
58 // is in progress.
59 void join();
60 // Removes the current thread from the set.
61 void leave();
62 // Returns "true" iff an suspension is in progress.
63 bool should_yield() { return _async_stop; }
64 // Suspends the current thread if a suspension is in progress (for
65 // the duration of the suspension.)
66 void yield(const char* id);
67 // Return when all threads in the set are suspended.
68 void suspend_all();
69 // Allow suspended threads to resume.
70 void resume_all();
71 // Redundant initializations okay.
72 void initialize() {
73 // Double-check dirty read idiom.
74 if (!_initialized) initialize_work();
75 }
76 };
79 class ConcurrentGCThread: public NamedThread {
80 friend class VMStructs;
82 protected:
83 bool _should_terminate;
84 bool _has_terminated;
86 enum CGC_flag_type {
87 CGC_nil = 0x0,
88 CGC_dont_suspend = 0x1,
89 CGC_CGC_safepoint = 0x2,
90 CGC_VM_safepoint = 0x4
91 };
93 static int _CGC_flag;
95 static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; }
96 static int set_CGC_flag(int b) { return _CGC_flag |= b; }
97 static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; }
99 // All instances share this one set.
100 static SuspendibleThreadSet _sts;
102 // Create and start the thread (setting it's priority high.)
103 void create_and_start();
105 // Do initialization steps in the thread: record stack base and size,
106 // init thread local storage, set JNI handle block.
107 void initialize_in_thread();
109 // Wait until Universe::is_fully_initialized();
110 void wait_for_universe_init();
112 // Record that the current thread is terminating, and will do more
113 // concurrent work.
114 void terminate();
116 public:
117 // Constructor
119 ConcurrentGCThread();
120 ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
122 // Tester
123 bool is_ConcurrentGC_thread() const { return true; }
125 static void safepoint_synchronize();
126 static void safepoint_desynchronize();
128 // All overridings should probably do _sts::yield, but we allow
129 // overriding for distinguished debugging messages. Default is to do
130 // nothing.
131 virtual void yield() {}
133 bool should_yield() { return _sts.should_yield(); }
135 // they are prefixed by sts since there are already yield() and
136 // should_yield() (non-static) methods in this class and it was an
137 // easy way to differentiate them.
138 static void stsYield(const char* id);
139 static bool stsShouldYield();
140 static void stsJoin();
141 static void stsLeave();
143 };
145 // The SurrogateLockerThread is used by concurrent GC threads for
146 // manipulating Java monitors, in particular, currently for
147 // manipulating the pending_list_lock. XXX
148 class SurrogateLockerThread: public JavaThread {
149 friend class VMStructs;
150 public:
151 enum SLT_msg_type {
152 empty = 0, // no message
153 acquirePLL, // acquire pending list lock
154 releaseAndNotifyPLL // notify and release pending list lock
155 };
156 private:
157 // the following are shared with the CMSThread
158 SLT_msg_type _buffer; // communication buffer
159 Monitor _monitor; // monitor controlling buffer
160 BasicLock _basicLock; // used for PLL locking
162 public:
163 static SurrogateLockerThread* make(TRAPS);
165 SurrogateLockerThread();
167 bool is_hidden_from_external_view() const { return true; }
169 void loop(); // main method
171 void manipulatePLL(SLT_msg_type msg);
173 };
175 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP