Skip to content

Commit a17ce44

Browse files
committed
8187547: PPC64: icache invalidation is incorrect in some places
Reviewed-by: mdoerr, goetz
1 parent b45c923 commit a17ce44

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/hotspot/cpu/ppc/macroAssembler_ppc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void MacroAssembler::calculate_address_from_global_toc(Register dst, address add
129129
}
130130
}
131131

132-
int MacroAssembler::patch_calculate_address_from_global_toc_at(address a, address bound, address addr) {
132+
address MacroAssembler::patch_calculate_address_from_global_toc_at(address a, address bound, address addr) {
133133
const int offset = MacroAssembler::offset_to_global_toc(addr);
134134

135135
const address inst2_addr = a;
@@ -155,7 +155,7 @@ int MacroAssembler::patch_calculate_address_from_global_toc_at(address a, addres
155155
assert(is_addis(inst1) && inv_ra_field(inst1) == 29 /* R29 */, "source must be global TOC");
156156
set_imm((int *)inst1_addr, MacroAssembler::largeoffset_si16_si16_hi(offset));
157157
set_imm((int *)inst2_addr, MacroAssembler::largeoffset_si16_si16_lo(offset));
158-
return (int)((intptr_t)addr - (intptr_t)inst1_addr);
158+
return inst1_addr;
159159
}
160160

161161
address MacroAssembler::get_address_of_calculate_address_from_global_toc_at(address a, address bound) {
@@ -201,7 +201,7 @@ address MacroAssembler::get_address_of_calculate_address_from_global_toc_at(addr
201201
// clrldi rx = rx & 0xFFFFffff // clearMS32b, optional
202202
// ori rx = rx | const.lo
203203
// Clrldi will be passed by.
204-
int MacroAssembler::patch_set_narrow_oop(address a, address bound, narrowOop data) {
204+
address MacroAssembler::patch_set_narrow_oop(address a, address bound, narrowOop data) {
205205
assert(UseCompressedOops, "Should only patch compressed oops");
206206

207207
const address inst2_addr = a;
@@ -227,7 +227,7 @@ int MacroAssembler::patch_set_narrow_oop(address a, address bound, narrowOop dat
227227

228228
set_imm((int *)inst1_addr, (short)(xc)); // see enc_load_con_narrow_hi/_lo
229229
set_imm((int *)inst2_addr, (xd)); // unsigned int
230-
return (int)((intptr_t)inst2_addr - (intptr_t)inst1_addr);
230+
return inst1_addr;
231231
}
232232

233233
// Get compressed oop or klass constant.

src/hotspot/cpu/ppc/macroAssembler_ppc.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ class MacroAssembler: public Assembler {
105105
};
106106

107107
inline static bool is_calculate_address_from_global_toc_at(address a, address bound);
108-
static int patch_calculate_address_from_global_toc_at(address a, address addr, address bound);
108+
// Returns address of first instruction in sequence.
109+
static address patch_calculate_address_from_global_toc_at(address a, address bound, address addr);
109110
static address get_address_of_calculate_address_from_global_toc_at(address a, address addr);
110111

111112
#ifdef _LP64
112113
// Patch narrow oop constant.
113114
inline static bool is_set_narrow_oop(address a, address bound);
114-
static int patch_set_narrow_oop(address a, address bound, narrowOop data);
115+
// Returns address of first instruction in sequence.
116+
static address patch_set_narrow_oop(address a, address bound, narrowOop data);
115117
static narrowOop get_narrow_oop(address a, address bound);
116118
#endif
117119

src/hotspot/cpu/ppc/nativeInst_ppc.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -221,13 +221,13 @@ address NativeMovConstReg::set_data_plain(intptr_t data, CodeBlob *cb) {
221221
// A calculation relative to the global TOC.
222222
if (MacroAssembler::get_address_of_calculate_address_from_global_toc_at(addr, cb->content_begin()) !=
223223
(address)data) {
224-
const int invalidated_range =
225-
MacroAssembler::patch_calculate_address_from_global_toc_at(addr, cb->content_begin(),
224+
const address inst2_addr = addr;
225+
const address inst1_addr =
226+
MacroAssembler::patch_calculate_address_from_global_toc_at(inst2_addr, cb->content_begin(),
226227
(address)data);
227-
const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
228-
// FIXME:
229-
const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
230-
ICache::ppc64_flush_icache_bytes(start, range);
228+
assert(inst1_addr != NULL && inst1_addr < inst2_addr, "first instruction must be found");
229+
const int range = inst2_addr - inst1_addr + BytesPerInstWord;
230+
ICache::ppc64_flush_icache_bytes(inst1_addr, range);
231231
}
232232
next_address = addr + 1 * BytesPerInstWord;
233233
} else if (MacroAssembler::is_load_const_at(addr)) {
@@ -288,15 +288,15 @@ void NativeMovConstReg::set_data(intptr_t data) {
288288
}
289289

290290
void NativeMovConstReg::set_narrow_oop(narrowOop data, CodeBlob *code /* = NULL */) {
291-
address addr = addr_at(0);
291+
address inst2_addr = addr_at(0);
292292
CodeBlob* cb = (code) ? code : CodeCache::find_blob(instruction_address());
293-
if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return;
294-
const int invalidated_range =
295-
MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data);
296-
const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
297-
// FIXME:
298-
const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
299-
ICache::ppc64_flush_icache_bytes(start, range);
293+
if (MacroAssembler::get_narrow_oop(inst2_addr, cb->content_begin()) == (long)data)
294+
return;
295+
const address inst1_addr =
296+
MacroAssembler::patch_set_narrow_oop(inst2_addr, cb->content_begin(), (long)data);
297+
assert(inst1_addr != NULL && inst1_addr < inst2_addr, "first instruction must be found");
298+
const int range = inst2_addr - inst1_addr + BytesPerInstWord;
299+
ICache::ppc64_flush_icache_bytes(inst1_addr, range);
300300
}
301301

302302
// Do not use an assertion here. Let clients decide whether they only

0 commit comments

Comments
 (0)