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 "classfile/stringTable.hpp"
27#include "classfile/systemDictionary.hpp"
28#include "gc/shared/weakProcessorPhases.hpp"
29#include "prims/resolvedMethodTable.hpp"
30#include "runtime/jniHandles.hpp"
31#include "utilities/debug.hpp"
32#include "utilities/macros.hpp"
33
34#if INCLUDE_JFR
35#include "jfr/jfr.hpp"
36#endif // INCLUDE_JFR
37
38#if INCLUDE_JVMTI
39#include "prims/jvmtiExport.hpp"
40#endif // INCLUDE_JVMTI
41
42WeakProcessorPhases::Phase WeakProcessorPhases::phase(uint value) {
43 assert(value < phase_count, "Invalid phase value %u", value);
44 return static_cast<Phase>(value);
45}
46
47uint WeakProcessorPhases::index(Phase phase) {
48 uint value = static_cast<uint>(phase);
49 assert(value < phase_count, "Invalid phase %u", value);
50 return value;
51}
52
53uint WeakProcessorPhases::serial_index(Phase phase) {
54 assert(is_serial(phase), "not serial phase %u", index(phase));
55 return index(phase) - serial_phase_start;
56}
57
58uint WeakProcessorPhases::oop_storage_index(Phase phase) {
59 assert(is_oop_storage(phase), "not oop storage phase %u", index(phase));
60 return index(phase) - oop_storage_phase_start;
61}
62
63bool WeakProcessorPhases::is_serial(Phase phase) {
64 // serial_phase_count is 0 if JFR and JVMTI are both not built,
65 // making this check with unsigned lhs redundant
66#if INCLUDE_JVMTI || INCLUDE_JFR
67 return (index(phase) - serial_phase_start) < serial_phase_count;
68#else
69 STATIC_ASSERT(serial_phase_count == 0);
70 return false;
71#endif
72}
73
74bool WeakProcessorPhases::is_oop_storage(Phase phase) {
75 return (index(phase) - oop_storage_phase_start) < oop_storage_phase_count;
76}
77
78const char* WeakProcessorPhases::description(Phase phase) {
79 switch (phase) {
80 JVMTI_ONLY(case jvmti: return "JVMTI weak processing";)
81 JFR_ONLY(case jfr: return "JFR weak processing";)
82 case jni: return "JNI weak processing";
83 case stringtable: return "StringTable weak processing";
84 case resolved_method_table: return "ResolvedMethodTable weak processing";
85 case vm: return "VM weak processing";
86 default:
87 ShouldNotReachHere();
88 return "Invalid weak processing phase";
89 }
90}
91
92WeakProcessorPhases::Processor WeakProcessorPhases::processor(Phase phase) {
93 switch (phase) {
94 JVMTI_ONLY(case jvmti: return &JvmtiExport::weak_oops_do;)
95 JFR_ONLY(case jfr: return &Jfr::weak_oops_do;)
96 default:
97 ShouldNotReachHere();
98 return NULL;
99 }
100}
101
102OopStorage* WeakProcessorPhases::oop_storage(Phase phase) {
103 switch (phase) {
104 case jni: return JNIHandles::weak_global_handles();
105 case stringtable: return StringTable::weak_storage();
106 case resolved_method_table: return ResolvedMethodTable::weak_storage();
107 case vm: return SystemDictionary::vm_weak_oop_storage();
108 default:
109 ShouldNotReachHere();
110 return NULL;
111 }
112}
113
114bool WeakProcessorPhases::is_stringtable(Phase phase) {
115 return phase == stringtable;
116}
117
118bool WeakProcessorPhases::is_resolved_method_table(Phase phase) {
119 return phase == resolved_method_table;
120}
121