Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/x86/c2_intelJccErratum_x86.cpp
41144 views
1
/*
2
* Copyright (c) 2020, 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 "asm/macroAssembler.hpp"
27
#include "c2_intelJccErratum_x86.hpp"
28
#include "opto/cfgnode.hpp"
29
#include "opto/compile.hpp"
30
#include "opto/machnode.hpp"
31
#include "opto/node.hpp"
32
#include "opto/output.hpp"
33
#include "opto/regalloc.hpp"
34
#include "utilities/align.hpp"
35
#include "utilities/debug.hpp"
36
37
// Compute which 32 byte boundary an address corresponds to
38
uintptr_t IntelJccErratum::boundary(uintptr_t addr) {
39
return addr >> 5;
40
}
41
42
bool IntelJccErratum::is_crossing_or_ending_at_32_byte_boundary(uintptr_t start_pc, uintptr_t end_pc) {
43
int jcc_size = int(end_pc - start_pc);
44
assert(jcc_size <= largest_jcc_size(), "invalid jcc size: %d", jcc_size);
45
return boundary(start_pc) != boundary(end_pc);
46
}
47
48
bool IntelJccErratum::is_jcc_erratum_branch(const MachNode* node) {
49
if (node->is_MachCall() && !node->is_MachCallJava()) {
50
return true;
51
}
52
return node->is_MachBranch();
53
}
54
55
int IntelJccErratum::jcc_erratum_taint_node(MachNode* node, PhaseRegAlloc* regalloc) {
56
node->add_flag(Node::PD::Flag_intel_jcc_erratum);
57
return node->size(regalloc);
58
}
59
60
int IntelJccErratum::tag_affected_machnodes(Compile* C, PhaseCFG* cfg, PhaseRegAlloc* regalloc) {
61
ResourceMark rm;
62
int nop_size = 0;
63
MachNode* last_m = NULL;
64
65
for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
66
const Block* const block = cfg->get_block(i);
67
for (uint j = 0; j < block->number_of_nodes(); ++j) {
68
const Node* const node = block->get_node(j);
69
if (!node->is_Mach()) {
70
continue;
71
}
72
MachNode* m = node->as_Mach();
73
if (is_jcc_erratum_branch(m)) {
74
// Found a root jcc erratum branch, flag it as problematic
75
nop_size += jcc_erratum_taint_node(m, regalloc);
76
77
if (!m->is_MachReturn() && !m->is_MachCall()) {
78
// We might fuse a problematic jcc erratum branch with a preceding
79
// ALU instruction - we must catch such problematic macro fusions
80
// and flag the ALU instruction as problematic too.
81
for (uint k = 1; k < m->req(); ++k) {
82
const Node* const use = m->in(k);
83
if (use == last_m && !m->is_MachReturn()) {
84
// Flag fused conditions too
85
nop_size += jcc_erratum_taint_node(last_m, regalloc);
86
}
87
}
88
}
89
last_m = NULL;
90
} else {
91
last_m = m;
92
}
93
}
94
}
95
return nop_size;
96
}
97
98
int IntelJccErratum::compute_padding(uintptr_t current_offset, const MachNode* mach, Block* block, uint index_in_block, PhaseRegAlloc* regalloc) {
99
int jcc_size = mach->size(regalloc);
100
if (index_in_block < block->number_of_nodes() - 1) {
101
Node* next = block->get_node(index_in_block + 1);
102
if (next->is_Mach() && (next->as_Mach()->flags() & Node::PD::Flag_intel_jcc_erratum)) {
103
jcc_size += mach->size(regalloc);
104
}
105
}
106
if (jcc_size > largest_jcc_size()) {
107
// Let's not try fixing this for nodes that seem unreasonably large
108
return false;
109
}
110
if (is_crossing_or_ending_at_32_byte_boundary(current_offset, current_offset + jcc_size)) {
111
return int(align_up(current_offset, 32) - current_offset);
112
} else {
113
return 0;
114
}
115
}
116
117
#define __ _masm.
118
119
uintptr_t IntelJccErratumAlignment::pc() {
120
return (uintptr_t)__ pc();
121
}
122
123
IntelJccErratumAlignment::IntelJccErratumAlignment(MacroAssembler& masm, int jcc_size) :
124
_masm(masm),
125
_start_pc(pc()) {
126
if (!VM_Version::has_intel_jcc_erratum()) {
127
return;
128
}
129
130
if (Compile::current()->output()->in_scratch_emit_size()) {
131
// When we measure the size of this 32 byte alignment, we apply a conservative guess.
132
__ nop(jcc_size);
133
} else if (IntelJccErratum::is_crossing_or_ending_at_32_byte_boundary(_start_pc, _start_pc + jcc_size)) {
134
// The affected branch might get slowed down by micro code mitigations
135
// as it could be susceptible to the erratum. Place nops until the next
136
// 32 byte boundary to make sure the branch will be cached.
137
const int alignment_nops = (int)(align_up(_start_pc, 32) - _start_pc);
138
__ nop(alignment_nops);
139
_start_pc = pc();
140
}
141
}
142
143
IntelJccErratumAlignment::~IntelJccErratumAlignment() {
144
if (!VM_Version::has_intel_jcc_erratum() ||
145
Compile::current()->output()->in_scratch_emit_size()) {
146
return;
147
}
148
149
assert(!IntelJccErratum::is_crossing_or_ending_at_32_byte_boundary(_start_pc, pc()), "Invalid jcc_size estimate");
150
}
151
152