1 /*
2 * Copyright (c) 2018, 2019, 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 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/oopStorageSet.hpp"
27 #include "gc/shared/weakProcessorPhases.hpp"
28 #include "utilities/debug.hpp"
29 #include "utilities/macros.hpp"
30
31 #if INCLUDE_JFR
32 #include "jfr/jfr.hpp"
33 #endif // INCLUDE_JFR
34
35 #if INCLUDE_JVMTI
36 #include "prims/jvmtiExport.hpp"
37 #endif // INCLUDE_JVMTI
38
39 // serial_phase_count is 0 if JFR and JVMTI are both not built,
40 // requiring some code to be careful to avoid tautological checks
41 // that some compilers warn about.
42
43 #define HAVE_SERIAL_PHASES (INCLUDE_JVMTI || INCLUDE_JFR)
44
45 WeakProcessorPhases::Phase WeakProcessorPhases::serial_phase(uint value) {
46 #if HAVE_SERIAL_PHASES
47 assert(value < serial_phase_count, "Invalid serial phase value %u", value);
48 return static_cast<Phase>(value + serial_phase_start);
49 #else
50 STATIC_ASSERT(serial_phase_count == 0);
51 fatal("invalid serial phase value %u", value);
52 return static_cast<Phase>(serial_phase_start);
53 #endif // HAVE_SERIAL_PHASES
54 }
55
56 WeakProcessorPhases::Phase WeakProcessorPhases::oopstorage_phase(uint value) {
57 assert(value < oopstorage_phase_count, "Invalid oopstorage phase value %u", value);
58 return static_cast<Phase>(value + oopstorage_phase_start);
59 }
60
61 static uint raw_phase_index(WeakProcessorPhases::Phase phase) {
62 return static_cast<uint>(phase);
63 }
64
65 uint WeakProcessorPhases::serial_index(Phase phase) {
66 assert(is_serial(phase), "not serial phase %u", raw_phase_index(phase));
67 return raw_phase_index(phase) - serial_phase_start;
68 }
69
70 uint WeakProcessorPhases::oopstorage_index(Phase phase) {
71 assert(is_oopstorage(phase), "not oopstorage phase %u", raw_phase_index(phase));
72 return raw_phase_index(phase) - oopstorage_phase_start;
73 }
74
75 static bool is_phase(WeakProcessorPhases::Phase phase, uint start, uint count) {
76 return (raw_phase_index(phase) - start) < count;
77 }
78
79 bool WeakProcessorPhases::is_serial(Phase phase) {
80 #if HAVE_SERIAL_PHASES
81 return is_phase(phase, serial_phase_start, serial_phase_count);
82 #else
83 STATIC_ASSERT(serial_phase_count == 0);
84 return false;
85 #endif // HAVE_SERIAL_PHASES
86 }
87
88 bool WeakProcessorPhases::is_oopstorage(Phase phase) {
89 return is_phase(phase, oopstorage_phase_start, oopstorage_phase_count);
90 }
91
92 #ifdef ASSERT
93
94 void WeakProcessorPhases::Iterator::verify_nonsingular() const {
95 assert(_limit != singular_value, "precondition");
96 }
97
98 void WeakProcessorPhases::Iterator::verify_category_match(const Iterator& other) const {
99 verify_nonsingular();
100 assert(_limit == other._limit, "precondition");
101 }
102
103 void WeakProcessorPhases::Iterator::verify_dereferenceable() const {
104 verify_nonsingular();
105 assert(_index < _limit, "precondition");
106 }
107
108 #endif // ASSERT
109
110 const char* WeakProcessorPhases::description(Phase phase) {
111 switch (phase) {
112 JVMTI_ONLY(case jvmti: return "JVMTI weak processing";)
113 JFR_ONLY(case jfr: return "JFR weak processing";)
114 default:
115 ShouldNotReachHere();
116 return "Invalid serial weak processing phase";
117 }
118 }
119
120 WeakProcessorPhases::Processor WeakProcessorPhases::processor(Phase phase) {
121 switch (phase) {
122 JVMTI_ONLY(case jvmti: return &JvmtiExport::weak_oops_do;)
123 JFR_ONLY(case jfr: return &Jfr::weak_oops_do;)
124 default:
125 ShouldNotReachHere();
126 return NULL;
127 }
128 }