13fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Copyright 2011 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// CPU specific code for ia32 independent of OS goes here. 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef __GNUC__ 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/third_party/valgrind/valgrind.h" 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#if V8_TARGET_ARCH_IA32 12f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/assembler.h" 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "src/macro-assembler.h" 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 { 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 19b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvoid CpuFeatures::FlushICache(void* start, size_t size) { 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // No need to flush the instruction cache on Intel. On Intel instruction 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // cache flushing is only necessary when multiple cores running the same 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // code simultaneously. V8 (and JavaScript) is single threaded and when code 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // is patched on an intel CPU the core performing the patching will have its 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // own instruction cache updated automatically. 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If flushing of the instruction cache becomes necessary Windows has the 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // API function FlushInstructionCache. 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // By default, valgrind only checks the stack for writes that might need to 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // invalidate already cached translated code. This leads to random 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // instability when code patches or moves are sometimes unnoticed. One 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // solution is to run valgrind with --smc-check=all, but this comes at a big 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // performance cost. We can notify valgrind to invalidate its cache. 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef VALGRIND_DISCARD_TRANSLATIONS 353fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch unsigned res = VALGRIND_DISCARD_TRANSLATIONS(start, size); 363fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch USE(res); 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace internal 41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch} // namespace v8 42f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 43f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke#endif // V8_TARGET_ARCH_IA32 44