1.1 --- a/src/os/linux/vm/os_linux.cpp Mon Mar 16 11:49:32 2015 -0700 1.2 +++ b/src/os/linux/vm/os_linux.cpp Thu Oct 12 21:27:07 2017 +0800 1.3 @@ -22,6 +22,12 @@ 1.4 * 1.5 */ 1.6 1.7 +/* 1.8 + * This file has been modified by Loongson Technology in 2015. These 1.9 + * modifications are Copyright (c) 2015 Loongson Technology, and are made 1.10 + * available on the same license terms set forth above. 1.11 + */ 1.12 + 1.13 // no precompiled headers 1.14 #include "classfile/classLoader.hpp" 1.15 #include "classfile/systemDictionary.hpp" 1.16 @@ -246,6 +252,8 @@ 1.17 #define SYS_gettid 186 1.18 #elif __sparc__ 1.19 #define SYS_gettid 143 1.20 +#elif __mips__ 1.21 +#define SYS_gettid 4222 1.22 #else 1.23 #error define gettid for the arch 1.24 #endif 1.25 @@ -266,6 +274,8 @@ 1.26 static char cpu_arch[] = "ppc"; 1.27 #elif defined(PPC64) 1.28 static char cpu_arch[] = "ppc64"; 1.29 +#elif defined(MIPS64) 1.30 +static char cpu_arch[] = "mipsel"; 1.31 #elif defined(SPARC) 1.32 # ifdef _LP64 1.33 static char cpu_arch[] = "sparcv9"; 1.34 @@ -354,7 +364,7 @@ 1.35 // 1: ... 1.36 // ... 1.37 // 7: The default directories, normally /lib and /usr/lib. 1.38 -#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) 1.39 +#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390) || defined(MIPS64)) 1.40 #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" 1.41 #else 1.42 #define DEFAULT_LIBPATH "/lib:/usr/lib" 1.43 @@ -1017,6 +1027,14 @@ 1.44 Monitor* sync_with_child = osthread->startThread_lock(); 1.45 MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag); 1.46 sync_with_child->notify(); 1.47 + 1.48 +#ifdef MIPS64 1.49 + /* 2013/11/5 Jin: To be accessed in NativeGeneralJump::patch_verified_entry() */ 1.50 + if (thread->is_Java_thread()) 1.51 + { 1.52 + ((JavaThread*)thread)->set_handle_wrong_method_stub(SharedRuntime::get_handle_wrong_method_stub()); 1.53 + } 1.54 +#endif 1.55 } 1.56 1.57 // Free Linux resources related to the OSThread 1.58 @@ -1942,6 +1960,7 @@ 1.59 {EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"}, 1.60 {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"}, 1.61 {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, 1.62 + {EM_MIPS, EM_MIPS, ELFCLASS64, ELFDATA2LSB, (char*)"MIPS64 LE"}, 1.63 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, 1.64 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} 1.65 }; 1.66 @@ -1956,6 +1975,8 @@ 1.67 static Elf32_Half running_arch_code=EM_SPARCV9; 1.68 #elif (defined __sparc) && (!defined _LP64) 1.69 static Elf32_Half running_arch_code=EM_SPARC; 1.70 + #elif (defined MIPS64) 1.71 + static Elf32_Half running_arch_code=EM_MIPS; 1.72 #elif (defined __powerpc64__) 1.73 static Elf32_Half running_arch_code=EM_PPC64; 1.74 #elif (defined __powerpc__) 1.75 @@ -1976,7 +1997,7 @@ 1.76 static Elf32_Half running_arch_code=EM_68K; 1.77 #else 1.78 #error Method os::dll_load requires that one of following is defined:\ 1.79 - IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K 1.80 + IA32, AMD64, IA64, __mips64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K 1.81 #endif 1.82 1.83 // Identify compatability class for VM's architecture and library's architecture 1.84 @@ -3267,7 +3288,7 @@ 1.85 1.86 #ifndef ZERO 1.87 large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M) 1.88 - ARM_ONLY(2 * M) PPC_ONLY(4 * M); 1.89 + ARM_ONLY(2 * M) PPC_ONLY(4 * M) MIPS64_ONLY(4 * M); //In MIPS _large_page_size is seted 4*M. 1.90 #endif // ZERO 1.91 1.92 FILE *fp = fopen("/proc/meminfo", "r"); 1.93 @@ -4791,7 +4812,12 @@ 1.94 Linux::fast_thread_clock_init(); 1.95 1.96 // Allocate a single page and mark it as readable for safepoint polling 1.97 +#ifdef OPT_SAFEPOINT 1.98 + void * p = (void *)(0x10000); 1.99 + address polling_page = (address) ::mmap(p, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 1.100 +#else 1.101 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 1.102 +#endif 1.103 guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" ); 1.104 1.105 os::set_polling_page( polling_page ); 1.106 @@ -4826,19 +4852,29 @@ 1.107 // size. Add a page for compiler2 recursion in main thread. 1.108 // Add in 2*BytesPerWord times page size to account for VM stack during 1.109 // class initialization depending on 32 or 64 bit VM. 1.110 + 1.111 + /* 2014/1/2 Liao: JDK8 requires larger -Xss option. 1.112 + * TongWeb cannot run with -Xss192K. 1.113 + * We are not sure whether this causes errors, so simply print a warning. */ 1.114 + size_t min_stack_allowed_jdk6 = os::Linux::min_stack_allowed; 1.115 os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed, 1.116 (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() + 1.117 (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size()); 1.118 1.119 size_t threadStackSizeInBytes = ThreadStackSize * K; 1.120 if (threadStackSizeInBytes != 0 && 1.121 - threadStackSizeInBytes < os::Linux::min_stack_allowed) { 1.122 + threadStackSizeInBytes < min_stack_allowed_jdk6) { 1.123 tty->print_cr("\nThe stack size specified is too small, " 1.124 "Specify at least %dk", 1.125 - os::Linux::min_stack_allowed/ K); 1.126 + min_stack_allowed_jdk6/ K); 1.127 return JNI_ERR; 1.128 } 1.129 1.130 + if (threadStackSizeInBytes != 0 && 1.131 + threadStackSizeInBytes < os::Linux::min_stack_allowed) { 1.132 + warning("JDK8 requires the stack size be at least %dk, the current value is %dk. " 1.133 + "Resize -Xss for best performance.", os::Linux::min_stack_allowed/ K, ThreadStackSize); 1.134 + } 1.135 // Make the stack size a multiple of the page size so that 1.136 // the yellow/red zones can be guarded. 1.137 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, 1.138 @@ -4960,10 +4996,40 @@ 1.139 } 1.140 }; 1.141 1.142 +#ifdef MIPS64 1.143 +/* 2016/9/18 Jin 1.144 + * Refer to: libnuma_init() */ 1.145 +int get_available_cpus() { 1.146 + typedef int (*numa_num_task_cpus_t)(void); 1.147 + static numa_num_task_cpus_t _numa_num_task_cpus; 1.148 + 1.149 + void *handle = dlopen("libnuma.so.1", RTLD_LAZY); 1.150 + 1.151 + if (handle == NULL) 1.152 + return sysconf(_SC_NPROCESSORS_ONLN); 1.153 + 1.154 + _numa_num_task_cpus = CAST_FROM_FN_PTR(numa_num_task_cpus_t, dlsym(handle, "numa_num_task_cpus")); 1.155 + 1.156 + if (_numa_num_task_cpus == NULL) { 1.157 + dlclose(handle); 1.158 + return sysconf(_SC_NPROCESSORS_ONLN); 1.159 + } 1.160 + 1.161 + int ret = _numa_num_task_cpus(); 1.162 + dlclose(handle); 1.163 + return ret; 1.164 +} 1.165 +#endif 1.166 + 1.167 int os::active_processor_count() { 1.168 // Linux doesn't yet have a (official) notion of processor sets, 1.169 // so just return the number of online processors. 1.170 +#ifdef MIPS64 1.171 + int online_cpus = get_available_cpus(); 1.172 +#else 1.173 int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); 1.174 +#endif 1.175 + 1.176 assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check"); 1.177 return online_cpus; 1.178 }