From 056da3e01175603b0ecd56fcbc0012d15ae8dc82 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 3 Aug 2015 09:54:50 -0400 Subject: [PATCH] Backed out changeset c8d9d720a30e (bug 1190077) for Android bustage. CLOSED TREE --HG-- rename : js/src/vm/Time.cpp => js/src/prmjtime.cpp rename : js/src/vm/Time.h => js/src/prmjtime.h extra : amend_source : f55a8e8fbb4d3ea33b999f906a1aeb756a7c4319 --- js/src/asmjs/AsmJSModule.cpp | 4 +- js/src/asmjs/AsmJSValidate.cpp | 3 +- js/src/builtin/AtomicsObject.cpp | 3 +- js/src/gc/Nursery.cpp | 2 +- js/src/gc/Statistics.cpp | 2 +- js/src/jscompartment.h | 2 +- js/src/jsdate.cpp | 2 +- js/src/jsfriendapi.cpp | 2 +- js/src/jsgc.cpp | 2 +- js/src/jsmath.cpp | 3 +- js/src/moz.build | 2 +- js/src/{vm/Time.cpp => prmjtime.cpp} | 2 +- js/src/prmjtime.h | 59 ++++++++++ js/src/shell/js.cpp | 2 +- js/src/vm/HelperThreads.cpp | 2 +- js/src/vm/SavedStacks.cpp | 2 +- js/src/vm/Time.h | 163 --------------------------- js/src/vm/TraceLogging.cpp | 36 +++--- js/src/vm/TypeInference.cpp | 2 +- 19 files changed, 99 insertions(+), 196 deletions(-) rename js/src/{vm/Time.cpp => prmjtime.cpp} (99%) create mode 100644 js/src/prmjtime.h delete mode 100644 js/src/vm/Time.h diff --git a/js/src/asmjs/AsmJSModule.cpp b/js/src/asmjs/AsmJSModule.cpp index bdd9cccee617..b8fcc8a30cbf 100644 --- a/js/src/asmjs/AsmJSModule.cpp +++ b/js/src/asmjs/AsmJSModule.cpp @@ -33,7 +33,7 @@ #ifdef XP_WIN # include "jswin.h" #endif - +#include "prmjtime.h" #include "builtin/AtomicsObject.h" #include "frontend/Parser.h" @@ -42,8 +42,6 @@ #include "js/Conversions.h" #include "js/MemoryMetrics.h" -#include "vm/Time.h" - #include "jsobjinlines.h" #include "frontend/ParseNode-inl.h" diff --git a/js/src/asmjs/AsmJSValidate.cpp b/js/src/asmjs/AsmJSValidate.cpp index 8a887888c668..877afbed0763 100644 --- a/js/src/asmjs/AsmJSValidate.cpp +++ b/js/src/asmjs/AsmJSValidate.cpp @@ -28,7 +28,7 @@ #include "jsmath.h" #include "jsprf.h" #include "jsutil.h" - +#include "prmjtime.h" #include "asmjs/AsmJSLink.h" #include "asmjs/AsmJSModule.h" @@ -45,7 +45,6 @@ #endif #include "vm/HelperThreads.h" #include "vm/Interpreter.h" -#include "vm/Time.h" #include "jsobjinlines.h" diff --git a/js/src/builtin/AtomicsObject.cpp b/js/src/builtin/AtomicsObject.cpp index 6b7d15b76728..0fd833532125 100644 --- a/js/src/builtin/AtomicsObject.cpp +++ b/js/src/builtin/AtomicsObject.cpp @@ -53,12 +53,13 @@ #include "jsapi.h" #include "jsfriendapi.h" +#include "prmjtime.h" + #include "asmjs/AsmJSModule.h" #include "jit/AtomicOperations.h" #include "js/Class.h" #include "vm/GlobalObject.h" #include "vm/SharedTypedArrayObject.h" -#include "vm/Time.h" #include "vm/TypedArrayObject.h" #include "jsobjinlines.h" diff --git a/js/src/gc/Nursery.cpp b/js/src/gc/Nursery.cpp index 69a062f33b3a..a1225c95a7e8 100644 --- a/js/src/gc/Nursery.cpp +++ b/js/src/gc/Nursery.cpp @@ -13,6 +13,7 @@ #include "jscompartment.h" #include "jsgc.h" #include "jsutil.h" +#include "prmjtime.h" #include "gc/GCInternals.h" #include "gc/Memory.h" @@ -22,7 +23,6 @@ #if defined(DEBUG) #include "vm/ScopeObject.h" #endif -#include "vm/Time.h" #include "vm/TypedArrayObject.h" #include "vm/TypeInference.h" diff --git a/js/src/gc/Statistics.cpp b/js/src/gc/Statistics.cpp index c0188ef5c6cf..1de7475baf41 100644 --- a/js/src/gc/Statistics.cpp +++ b/js/src/gc/Statistics.cpp @@ -17,12 +17,12 @@ #include "jsprf.h" #include "jsutil.h" +#include "prmjtime.h" #include "gc/Memory.h" #include "vm/Debugger.h" #include "vm/HelperThreads.h" #include "vm/Runtime.h" -#include "vm/Time.h" using namespace js; using namespace js::gc; diff --git a/js/src/jscompartment.h b/js/src/jscompartment.h index ef41944300ca..9e4051874fd2 100644 --- a/js/src/jscompartment.h +++ b/js/src/jscompartment.h @@ -10,13 +10,13 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/Variant.h" +#include "prmjtime.h" #include "builtin/RegExp.h" #include "gc/Barrier.h" #include "gc/Zone.h" #include "vm/GlobalObject.h" #include "vm/PIC.h" #include "vm/SavedStacks.h" -#include "vm/Time.h" namespace js { diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 9d5282e796a7..ef2add7e242e 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -33,6 +33,7 @@ #include "jstypes.h" #include "jsutil.h" #include "jswrapper.h" +#include "prmjtime.h" #include "js/Conversions.h" #include "js/Date.h" @@ -41,7 +42,6 @@ #include "vm/Interpreter.h" #include "vm/String.h" #include "vm/StringBuffer.h" -#include "vm/Time.h" #include "jsobjinlines.h" diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index f71c8d67d09c..5d39a43980fa 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -18,12 +18,12 @@ #include "jswatchpoint.h" #include "jsweakmap.h" #include "jswrapper.h" +#include "prmjtime.h" #include "builtin/TestingFunctions.h" #include "js/Proxy.h" #include "proxy/DeadObjectProxy.h" #include "vm/ArgumentsObject.h" -#include "vm/Time.h" #include "vm/WeakMapObject.h" #include "vm/WrapperObject.h" diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 06716fa26773..80d43caab13c 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -210,6 +210,7 @@ #ifdef XP_WIN # include "jswin.h" #endif +#include "prmjtime.h" #include "gc/FindSCCs.h" #include "gc/GCInternals.h" @@ -226,7 +227,6 @@ #include "vm/Shape.h" #include "vm/String.h" #include "vm/Symbol.h" -#include "vm/Time.h" #include "vm/TraceLogging.h" #include "vm/WrapperObject.h" diff --git a/js/src/jsmath.cpp b/js/src/jsmath.cpp index a92f8eabd80c..3d1c7aa7bbf7 100644 --- a/js/src/jsmath.cpp +++ b/js/src/jsmath.cpp @@ -33,11 +33,10 @@ #include "jscompartment.h" #include "jslibmath.h" #include "jstypes.h" +#include "prmjtime.h" #include "js/Class.h" -#include "vm/Time.h" - #include "jsobjinlines.h" #if defined(ANDROID) || defined(XP_MACOSX) || defined(__DragonFly__) || \ diff --git a/js/src/moz.build b/js/src/moz.build index 6aaf2e7d2e75..ade842ea3387 100644 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -267,6 +267,7 @@ UNIFIED_SOURCES += [ 'jswatchpoint.cpp', 'jsweakmap.cpp', 'perf/jsperf.cpp', + 'prmjtime.cpp', 'proxy/BaseProxyHandler.cpp', 'proxy/CrossCompartmentWrapper.cpp', 'proxy/DeadObjectProxy.cpp', @@ -317,7 +318,6 @@ UNIFIED_SOURCES += [ 'vm/StringBuffer.cpp', 'vm/StructuredClone.cpp', 'vm/Symbol.cpp', - 'vm/Time.cpp', 'vm/TypedArrayObject.cpp', 'vm/TypeInference.cpp', 'vm/UbiNode.cpp', diff --git a/js/src/vm/Time.cpp b/js/src/prmjtime.cpp similarity index 99% rename from js/src/vm/Time.cpp rename to js/src/prmjtime.cpp index 69e2cc41d236..237279112bbc 100644 --- a/js/src/vm/Time.cpp +++ b/js/src/prmjtime.cpp @@ -6,7 +6,7 @@ /* PR time code. */ -#include "vm/Time.h" +#include "prmjtime.h" #include "mozilla/DebugOnly.h" #include "mozilla/MathAlgorithms.h" diff --git a/js/src/prmjtime.h b/js/src/prmjtime.h new file mode 100644 index 000000000000..db57e66e42ff --- /dev/null +++ b/js/src/prmjtime.h @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * vim: set ts=8 sts=4 et sw=4 tw=99: + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef prmjtime_h +#define prmjtime_h + +#include +#include + +/* + * Broken down form of 64 bit time value. + */ +struct PRMJTime { + int32_t tm_usec; /* microseconds of second (0-999999) */ + int8_t tm_sec; /* seconds of minute (0-59) */ + int8_t tm_min; /* minutes of hour (0-59) */ + int8_t tm_hour; /* hour of day (0-23) */ + int8_t tm_mday; /* day of month (1-31) */ + int8_t tm_mon; /* month of year (0-11) */ + int8_t tm_wday; /* 0=sunday, 1=monday, ... */ + int32_t tm_year; /* absolute year, AD */ + int16_t tm_yday; /* day of year (0 to 365) */ + int8_t tm_isdst; /* non-zero if DST in effect */ +}; + +/* Some handy constants */ +#define PRMJ_USEC_PER_SEC 1000000L +#define PRMJ_USEC_PER_MSEC 1000L + +/* Return the current local time in micro-seconds */ +extern int64_t +PRMJ_Now(); + +/* Initialize the resources associated with PRMJ_Now. */ +#if defined(XP_WIN) +extern void +PRMJ_NowInit(); +#else +inline void +PRMJ_NowInit() {} +#endif + +/* Release the resources associated with PRMJ_Now; don't call PRMJ_Now again */ +#ifdef XP_WIN +extern void +PRMJ_NowShutdown(); +#else +inline void +PRMJ_NowShutdown() {} +#endif + +/* Format a time value into a buffer. Same semantics as strftime() */ +extern size_t +PRMJ_FormatTime(char* buf, int buflen, const char* fmt, PRMJTime* tm); + +#endif /* prmjtime_h */ diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 49982e608bd3..39587c09cc56 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -55,6 +55,7 @@ # include "jswin.h" #endif #include "jswrapper.h" +#include "prmjtime.h" #include "builtin/TestingFunctions.h" #include "frontend/Parser.h" @@ -76,7 +77,6 @@ #include "vm/Monitor.h" #include "vm/Shape.h" #include "vm/SharedArrayObject.h" -#include "vm/Time.h" #include "vm/TypedArrayObject.h" #include "vm/WrapperObject.h" diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index a3b35b2a009f..33fba5e2b524 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -10,12 +10,12 @@ #include "jsnativestack.h" #include "jsnum.h" // For FIX_FPU() +#include "prmjtime.h" #include "frontend/BytecodeCompiler.h" #include "gc/GCInternals.h" #include "jit/IonBuilder.h" #include "vm/Debugger.h" -#include "vm/Time.h" #include "vm/TraceLogging.h" #include "jscntxtinlines.h" diff --git a/js/src/vm/SavedStacks.cpp b/js/src/vm/SavedStacks.cpp index bd8a6ac4df66..70447841b5cb 100644 --- a/js/src/vm/SavedStacks.cpp +++ b/js/src/vm/SavedStacks.cpp @@ -20,13 +20,13 @@ #include "jsmath.h" #include "jsnum.h" #include "jsscript.h" +#include "prmjtime.h" #include "gc/Marking.h" #include "gc/Rooting.h" #include "js/Vector.h" #include "vm/Debugger.h" #include "vm/StringBuffer.h" -#include "vm/Time.h" #include "vm/WrapperObject.h" #include "jscntxtinlines.h" diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h deleted file mode 100644 index f16dfae609b1..000000000000 --- a/js/src/vm/Time.h +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * vim: set ts=8 sts=4 et sw=4 tw=99: - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef vm_Time_h -#define vm_Time_h - -#include -#include - -/* - * Broken down form of 64 bit time value. - */ -struct PRMJTime { - int32_t tm_usec; /* microseconds of second (0-999999) */ - int8_t tm_sec; /* seconds of minute (0-59) */ - int8_t tm_min; /* minutes of hour (0-59) */ - int8_t tm_hour; /* hour of day (0-23) */ - int8_t tm_mday; /* day of month (1-31) */ - int8_t tm_mon; /* month of year (0-11) */ - int8_t tm_wday; /* 0=sunday, 1=monday, ... */ - int32_t tm_year; /* absolute year, AD */ - int16_t tm_yday; /* day of year (0 to 365) */ - int8_t tm_isdst; /* non-zero if DST in effect */ -}; - -/* Some handy constants */ -#define PRMJ_USEC_PER_SEC 1000000L -#define PRMJ_USEC_PER_MSEC 1000L - -/* Return the current local time in micro-seconds */ -extern int64_t -PRMJ_Now(); - -/* Initialize the resources associated with PRMJ_Now. */ -#if defined(XP_WIN) -extern void -PRMJ_NowInit(); -#else -inline void -PRMJ_NowInit() {} -#endif - -/* Release the resources associated with PRMJ_Now; don't call PRMJ_Now again */ -#ifdef XP_WIN -extern void -PRMJ_NowShutdown(); -#else -inline void -PRMJ_NowShutdown() {} -#endif - -/* Format a time value into a buffer. Same semantics as strftime() */ -extern size_t -PRMJ_FormatTime(char* buf, int buflen, const char* fmt, PRMJTime* tm); - - -/** - * Requesting the number of cycles from the CPU. - * - * `rdtsc`, or Read TimeStamp Cycle, is an instruction provided by - * x86-compatible CPUs that lets processes request the number of - * cycles spent by the CPU executing instructions since the CPU was - * started. It may be used for performance monitoring, but you should - * be aware of the following limitations. - * - * - * 1. The value is *not* monotonic. - * - * The value is reset to 0 whenever a CPU is turned off (e.g. computer - * in full hibernation, single CPU going turned off). Moreover, on - * multi-core/multi-CPU architectures, the cycles of each core/CPU are - * generally not synchronized. Therefore, is a process or thread is - * rescheduled to another core/CPU, the result of `rdtsc` may decrease - * arbitrarily. - * - * The only way to prevent this is to pin your thread to a particular - * CPU, which is generally not a good idea. - * - * - * - * 2. The value increases independently. - * - * The value may increase whenever the CPU executes an instruction, - * regardless of the process that has issued this - * instruction. Moreover, if a process or thread is rescheduled to - * another core/CPU, the result of `rdtsc` may increase arbitrarily. - * - * The only way to prevent this is to ensure that your thread is the - * sole owner of the CPU. See [1] for an example. This is also - * generally not a good idea. - * - * - * - * 3. The value does not measure time. - * - * On older architectures (pre-Pentium 4), there was no constant mapping - * between rdtsc and CPU time. - * - * - * 4. Instructions may be reordered. - * - * The CPU can reorder instructions. Also, rdtsc does not necessarily - * wait until all previous instructions have finished executing before - * reading the counter. Similarly, subsequent instructions may begin - * execution before the read operation is performed. If you use rdtsc - * for micro-benchmarking, you may end up measuring something else - * than what you expect. See [1] for a study of countermeasures. - * - * - * ** Performance - * - * According to unchecked sources on the web, the overhead of rdtsc is - * expected to be 150-200 cycles on old architectures, 6-50 on newer - * architectures. Agner's instruction tables [2] seem to confirm the latter - * results. - * - * - * [1] - * http://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf - * [2] http://www.agner.org/optimize/instruction_tables.pdf - */ - -#define MOZ_HAVE_RDTSC 1 - -#if defined(_WIN32) - -#include -static __inline uint64_t -ReadTimestampCounter(void) -{ - return __rdtsc(); -} - -#elif defined(__i386__) - -static __inline__ uint64_t -ReadTimestampCounter(void) -{ - uint64_t x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} - -#elif defined(__x86_64__) - -static __inline__ uint64_t -ReadTimestampCounter(void) -{ - unsigned hi, lo; - __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); - return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 ); -} - -#else - -#undef MOZ_HAVE_RDTSC 1 - -#endif - -#endif /* vm_Time_h */ diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp index 25a363d233be..a1c43ebe53b9 100644 --- a/js/src/vm/TraceLogging.cpp +++ b/js/src/vm/TraceLogging.cpp @@ -17,7 +17,6 @@ #include "jit/BaselineJIT.h" #include "jit/CompileWrappers.h" #include "vm/Runtime.h" -#include "vm/Time.h" #include "vm/TraceLoggingGraph.h" #include "jit/JitFrames-inl.h" @@ -30,12 +29,29 @@ using mozilla::NativeEndian; TraceLoggerThreadState* traceLoggerState = nullptr; -#if defined(MOZ_HAVE_RDTSC) - -uint64_t inline rdtsc() { - return ReadTimestampCounter(); +#if defined(_WIN32) +#include +static __inline uint64_t +rdtsc(void) +{ + return __rdtsc(); +} +#elif defined(__i386__) +static __inline__ uint64_t +rdtsc(void) +{ + uint64_t x; + __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); + return x; +} +#elif defined(__x86_64__) +static __inline__ uint64_t +rdtsc(void) +{ + unsigned hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 ); } - #elif defined(__powerpc__) static __inline__ uint64_t rdtsc(void) @@ -56,12 +72,9 @@ rdtsc(void) result = result|lower; return result; - } #elif defined(__arm__) - #include - static __inline__ uint64_t rdtsc(void) { @@ -72,16 +85,13 @@ rdtsc(void) ret += tv.tv_usec; return ret; } - #else - static __inline__ uint64_t rdtsc(void) { return 0; } - -#endif // defined(MOZ_HAVE_RDTSC) +#endif class AutoTraceLoggerThreadStateLock { diff --git a/js/src/vm/TypeInference.cpp b/js/src/vm/TypeInference.cpp index 77c81da36f40..fcc2513088c6 100644 --- a/js/src/vm/TypeInference.cpp +++ b/js/src/vm/TypeInference.cpp @@ -19,6 +19,7 @@ #include "jsprf.h" #include "jsscript.h" #include "jsstr.h" +#include "prmjtime.h" #include "gc/Marking.h" #include "jit/BaselineJIT.h" @@ -31,7 +32,6 @@ #include "vm/HelperThreads.h" #include "vm/Opcodes.h" #include "vm/Shape.h" -#include "vm/Time.h" #include "vm/UnboxedObject.h" #include "jsatominlines.h"