1 /*
2 * Copyright (c) 2024, 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 #ifndef SHARE_OOPS_RECOMPILATION_SCHEDULE_HPP
26 #define SHARE_OOPS_RECOMPILATION_SCHEDULE_HPP
27
28 #include "cds/serializeClosure.hpp"
29 #include "memory/allStatic.hpp"
30 #include "memory/metaspaceClosure.hpp"
31 #include "oops/array.hpp"
32 #include "oops/trainingData.hpp"
33 #include "runtime/atomicAccess.hpp"
34 #include "utilities/exceptions.hpp"
35 #include "utilities/macros.hpp"
36 #include "utilities/ostream.hpp"
37
38 class RecompilationSchedule : public AllStatic {
39 static Array<MethodTrainingData*>* _schedule;
40 static Array<MethodTrainingData*>* _schedule_for_dumping;
41 static volatile bool* _status;
42 public:
43 static void initialize();
44 static void prepare(TRAPS);
45 static bool have_schedule() { return _schedule != nullptr; }
46 static Array<MethodTrainingData*>* schedule() { return _schedule; }
47 static int length() {
48 return have_schedule() ? _schedule->length() : 0;
49 }
50 static MethodTrainingData* at(int i) {
51 assert(i < length(), "");
52 return schedule()->at(i);
53 }
54 static volatile bool* status() { return _status; }
55 static volatile bool* status_adr_at(int i) {
56 assert(i < length(), "");
57 return &_status[i];
58 }
59 static bool status_at(int i) {
60 return AtomicAccess::load_acquire(status_adr_at(i));
61 }
62 static void set_status_at(int i, bool value) {
63 AtomicAccess::release_store(RecompilationSchedule::status_adr_at(i), value);
64 }
65 static bool claim_at(int i) {
66 return AtomicAccess::cmpxchg(RecompilationSchedule::status_adr_at(i), false, true) == false;
67 }
68 #if INCLUDE_CDS
69 static void iterate_roots(MetaspaceClosure* it);
70 static void cleanup();
71 static void serialize(SerializeClosure* soc);
72 static void print_archived_training_data_on(outputStream* st);
73 #endif
74 };
75
76 #endif // SHARE_OOPS_RECOMPILATION_SCHEDULE_HPP