int result = mprotect(reinterpret_cast<void*>(base), len, PROT_READ | PROT_WRITE | PROT_EXEC);
CHECK_EQ(result, 0);
- // Flush instruction cache
- // Only uses __builtin___clear_cache if GCC >= 4.3.3
-#if GCC_VERSION >= 40303
- __builtin___clear_cache(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len));
-#else
- // Only warn if not Intel as Intel doesn't have cache flush instructions.
-#if !defined(__i386__) && !defined(__x86_64__)
- UNIMPLEMENTED(WARNING) << "cache flush";
-#endif
-#endif
+ FlushInstructionCache(reinterpret_cast<char*>(base), reinterpret_cast<char*>(base + len));
}
void CommonCompilerTest::MakeExecutable(mirror::ClassLoader* class_loader, const char* class_name) {
code_size);
}
- __builtin___clear_cache(reinterpret_cast<char*>(code_ptr),
- reinterpret_cast<char*>(code_ptr + code_size));
+ FlushInstructionCache(reinterpret_cast<char*>(code_ptr),
+ reinterpret_cast<char*>(code_ptr + code_size));
number_of_compilations_++;
}
// We need to update the entry point in the runnable state for the instrumentation.
// Sleep forever and never come back.
NO_RETURN void SleepForever();
+inline void FlushInstructionCache(char* begin, char* end) {
+ // Only use __builtin___clear_cache with Clang or with GCC >= 4.3.0
+ // (__builtin___clear_cache was introduced in GCC 4.3.0).
+#if defined(__clang__) || GCC_VERSION >= 40300
+ __builtin___clear_cache(begin, end);
+#else
+ // Only warn on non-Intel platforms, as x86 and x86-64 do not need
+ // cache flush instructions, as long as the "code uses the same
+ // linear address for modifying and fetching the instruction". See
+ // "Intel(R) 64 and IA-32 Architectures Software Developer's Manual
+ // Volume 3A: System Programming Guide, Part 1", section 11.6
+ // "Self-Modifying Code".
+#if !defined(__i386__) && !defined(__x86_64__)
+ UNIMPLEMENTED(WARNING) << "cache flush";
+#endif
+#endif
+}
+
} // namespace art
#endif // ART_RUNTIME_UTILS_H_