Make TraceMonkey build on Solaris x86 with Sun Studio 12 (bug 452588, r=danderson).
authorGinn Chen <ginn.chen@sun.com>
Fri, 05 Sep 2008 16:56:03 -0700
changeset 19058 f821f6cfe0435bb631f6a1b62fe18e213e6a33fc
parent 19057 2d62584acb4f0272763221d3336442cfc85fc772
child 19059 0d0354ea085b7d3054a36a877951a51a3cc55886
child 19069 8bd3a8c5fb5a223ba2ffb5fc661441175ab86273
push id1930
push usermrbkap@mozilla.com
push dateWed, 10 Sep 2008 06:40:47 +0000
treeherderautoland@ee61af1469cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdanderson
bugs452588
milestone1.9.1b1pre
Make TraceMonkey build on Solaris x86 with Sun Studio 12 (bug 452588, r=danderson).
js/src/Makefile.in
js/src/jstracer.cpp
js/src/nanojit/LIR.h
js/src/nanojit/Nativei386.cpp
js/src/nanojit/avmplus.h
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -429,16 +429,28 @@ endif
 endif
 
 ifdef MOZ_MEMORY
 ifeq ($(OS_ARCH),Darwin)
 LDFLAGS += -ljemalloc
 endif
 endif
 
+# Sun Studio x86 has an optimization bug with LIR.cpp, use -xO2 instead.
+ifeq ($(OS_ARCH),SunOS)
+ifeq (86,$(findstring 86,$(OS_TEST)))
+ifndef GNU_CC
+LIR.o: LIR.cpp Makefile.in
+    $(REPORT_BUILD)
+    @$(MAKE_DEPS_AUTO_CXX)
+    $(CXX) -o $@ -c $(patsubst -xO%,-xO2,$(COMPILE_CFLAGS)) $<
+endif
+endif
+endif
+
 # Allow building jsinterp.c with special optimization flags
 ifdef INTERP_OPTIMIZER
 jsinterp.$(OBJ_SUFFIX): MODULE_OPTIMIZE_FLAGS=$(INTERP_OPTIMIZER)
 endif
 
 ifeq ($(OS_ARCH),IRIX)
 ifndef GNU_CC
 _COMPILE_CFLAGS  = $(patsubst -O%,-O1,$(COMPILE_CFLAGS))
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -42,16 +42,19 @@
 #include "jsstddef.h"           // always first
 #include "jsbit.h"              // low-level (NSPR-based) headers next
 #include "jsprf.h"
 #include <math.h>               // standard headers next
 #ifdef _MSC_VER
 #include <malloc.h>
 #define alloca _alloca
 #endif
+#ifdef SOLARIS
+#include <alloca.h>
+#endif
 
 #include "nanojit/avmplus.h"    // nanojit
 #include "nanojit/nanojit.h"
 #include "jsarray.h"            // higher-level library and API headers
 #include "jsbool.h"
 #include "jscntxt.h"
 #include "jsdbgapi.h"
 #include "jsemit.h"
@@ -2543,16 +2546,25 @@ js_CheckForSSE2()
         "mov $0x01, %%eax\n"
         "cpuid\n"
         "mov %%edx, %0\n"
         "popa\n"
         : "=m" (features)
         /* We have no inputs */
         /* We don't clobber anything */
        );
+#elif defined __SUNPRO_C || defined __SUNPRO_CC
+    asm("push %%ebx\n"
+        "mov $0x01, %%eax\n"
+        "cpuid\n"
+        "pop %%ebx\n"
+        : "=d" (features)
+        : /* We have no inputs */
+        : "%eax", "%ecx"
+       );
 #endif
     return (features & (1<<26)) != 0;
 }
 #endif
 
 extern void
 js_InitJIT(JSTraceMonitor *tm)
 {
--- a/js/src/nanojit/LIR.h
+++ b/js/src/nanojit/LIR.h
@@ -176,17 +176,21 @@ namespace nanojit
 			uint32_t		oprnd_3:8;	// only used for store, since this location gets clobbered during generation
 			uint32_t		oprnd_1:8;  // 256 ins window and since they only point backwards this is sufficient.
 			uint32_t		oprnd_2:8;  
 		};
 
         struct sti_type
         {
 			LOpcode			code:8;
+#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+			signed int      disp:8;     // Sun Studio requires explicitly declaring signed int bit-field
+#else
 			int32_t	    	disp:8;
+#endif
 			uint32_t		oprnd_1:8;  // 256 ins window and since they only point backwards this is sufficient.
 			uint32_t		oprnd_2:8;  
         };
 
 		// imm8 form 
 		struct c_type
 		{
 			LOpcode			code:8;
@@ -194,25 +198,33 @@ namespace nanojit
 			uint32_t		imm8a:8;
 			uint32_t		imm8b:8;  
 		};
 
         // imm24 form for short tramp & skip
         struct t_type
         {
             LOpcode         code:8;
+#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+            signed int      imm24:24;
+#else
             int32_t         imm24:24;
+#endif
         };
 
 		// imm16 form
 		struct i_type
 		{
 			LOpcode			code:8;
 			uint32_t		resv:8;  // cobberred during assembly
+#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+			signed int		imm16:16;
+#else
 			int32_t			imm16:16;
+#endif
 		};
 
 		// overlay used during code generation ( note that last byte is reserved for allocation )
 		struct g_type
 		{
 			LOpcode			code:8;
 			uint32_t		resv:8;   // cobberred during assembly
 			uint32_t		unused:16;
--- a/js/src/nanojit/Nativei386.cpp
+++ b/js/src/nanojit/Nativei386.cpp
@@ -342,17 +342,21 @@ namespace nanojit
 	void Assembler::nMarkExecute(Page* page, int32_t count, bool enable)
 	{
 		#if defined WIN32 || defined WIN64
 			DWORD dwIgnore;
 			VirtualProtect(&page->code, count*NJ_PAGE_SIZE, PAGE_EXECUTE_READWRITE, &dwIgnore);
 		#elif defined AVMPLUS_UNIX
 			intptr_t addr = (intptr_t)&page->code;
 			addr &= ~((uintptr_t)NJ_PAGE_SIZE - 1);
+			#if defined SOLARIS
+			if (mprotect((char *)addr, count*NJ_PAGE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
+			#else
 			if (mprotect((void *)addr, count*NJ_PAGE_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
+			#endif
                 AvmDebugLog(("FATAL ERROR: mprotect(PROT_EXEC) failed\n"));
                 abort();
             }
 		#endif
 			(void)enable;
 	}
 			
 	Register Assembler::nRegisterAllocFromSet(int set)
@@ -886,17 +890,24 @@ namespace nanojit
 				/* We need this case on AMD64, because it's possible that 
 				 * an earlier instruction has done a quadword load and reserved a 
 				 * GPR.  If so, ask for a new register.
 				 */
 				ra = findRegFor(lhs, XmmRegs);
 			}
 			// else, rA already has a register assigned.
 
+#if defined __SUNPRO_CC
+			// from Sun Studio C++ Readme: #pragma align inside namespace requires mangled names
+			static uint32_t temp[] = {0, 0, 0, 0, 0, 0, 0};
+			static uint32_t *negateMask = (uint32_t *)alignUp(temp, 16);
+			negateMask[1] = 0x80000000;
+#else
 			static const AVMPLUS_ALIGN16(uint32_t) negateMask[] = {0,0x80000000,0,0};
+#endif
 			SSE_XORPD(rr, negateMask);
 
 			if (rr != ra)
 				SSE_MOVSD(rr, ra);
 #if defined NANOJIT_IA32
 		}
 		else
 		{
--- a/js/src/nanojit/avmplus.h
+++ b/js/src/nanojit/avmplus.h
@@ -94,35 +94,42 @@ typedef JSInt16  int16_t;
 typedef JSUint32 uint32_t;
 typedef JSInt32  int32_t;
 typedef JSUint64 uint64_t;
 typedef JSInt64  int64_t;
 #else
 #include <stdint.h>
 #endif
 
-#if defined(_MSC_VER) && defined(AVMPLUS_IA32)
+#if defined(AVMPLUS_IA32)
+#if defined(_MSC_VER)
 __declspec(naked) static inline __int64 rdtsc()
 {
     __asm
     {
         rdtsc;
         ret;
     }
 }
-#endif
-
-#if defined(__i386__)
-
+#elif defined(SOLARIS)
+static inline unsigned long long rdtsc(void)
+{
+    unsigned long long int x;
+    asm volatile (".byte 0x0f, 0x31" : "=A" (x));
+    return x;
+}
+#elif defined(__i386__)
 static __inline__ unsigned long long rdtsc(void)
 {
   unsigned long long int x;
      __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
      return x;
 }
+#endif /* compilers */
+
 #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 );
 }
@@ -146,17 +153,17 @@ static __inline__ unsigned long long rdt
                 );
   result = upper;
   result = result<<32;
   result = result|lower;
 
   return(result);
 }
 
-#endif
+#endif /* architecture */
 
 struct JSContext;
 
 namespace nanojit
 {
 	class Fragment;
 
 	enum ExitType {
@@ -268,17 +275,21 @@ public:
     }
     
     inline void
     Free(void* p, uint32_t pages)
     {
 #ifdef XP_WIN
         VirtualFree(p, 0, MEM_RELEASE);
 #elif defined AVMPLUS_UNIX
+        #if defined SOLARIS
+        munmap((char*)p, pages * kNativePageSize); 
+        #else
         munmap(p, pages * kNativePageSize); 
+        #endif
 #else
         free(p);
 #endif
     }
     
 };
 
 class GC