8227338: templateInterpreter.cpp: copy_table() needs to be safer

Reviewed-by: dholmes, eosterlund, sspitsyn, kbarrett
This commit is contained in:
Daniel D. Daugherty 2019-07-10 10:18:06 -04:00
parent f7d689f4bc
commit d3ab43a5f4

View file

@ -31,7 +31,9 @@
#include "interpreter/templateTable.hpp"
#include "logging/log.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/timerTrace.hpp"
#include "utilities/copy.hpp"
#ifndef CC_INTERP
@ -275,11 +277,17 @@ int TemplateInterpreter::TosState_as_index(TosState state) {
//------------------------------------------------------------------------------------------------------------------------
// Safepoint suppport
// Safepoint support
static inline void copy_table(address* from, address* to, int size) {
// Copy non-overlapping tables. The copy has to occur word wise for MT safety.
while (size-- > 0) *to++ = *from++;
// Copy non-overlapping tables.
if (SafepointSynchronize::is_at_safepoint()) {
// Nothing is using the table at a safepoint so skip atomic word copy.
Copy::disjoint_words((HeapWord*)from, (HeapWord*)to, (size_t)size);
} else {
// Use atomic word copy when not at a safepoint for safety.
Copy::disjoint_words_atomic((HeapWord*)from, (HeapWord*)to, (size_t)size);
}
}
void TemplateInterpreter::notice_safepoints() {