1 /* 2 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 public: 26 // Java Thread - force inlining 27 static inline Thread* thread() ; 28 29 private: 30 static Thread* _get_thread_cache[]; // index by [(raw_id>>9)^(raw_id>>20) % _pd_cache_size] 31 static Thread* get_thread_via_cache_slowly(uintptr_t raw_id, int index); 32 33 NOT_PRODUCT(static int _tcacheHit;) 34 NOT_PRODUCT(static int _tcacheMiss;) 35 36 public: 37 38 // Print cache hit/miss statistics 39 static void print_statistics() PRODUCT_RETURN; 40 41 enum Constants { 42 _pd_cache_size = 256*2 // projected typical # of threads * 2 43 }; 44 45 static void set_thread_in_slot (Thread *) ; 46 47 static uintptr_t pd_raw_thread_id() { 48 return _raw_thread_id(); 49 } 50 51 static int pd_cache_index(uintptr_t raw_id) { 52 // Hash function: From email from Dave: 53 // The hash function deserves an explanation. %g7 points to libthread's 54 // "thread" structure. On T1 the thread structure is allocated on the 55 // user's stack (yes, really!) so the ">>20" handles T1 where the JVM's 56 // stack size is usually >= 1Mb. The ">>9" is for T2 where Roger allocates 57 // globs of thread blocks contiguously. The "9" has to do with the 58 // expected size of the T2 thread structure. If these constants are wrong 59 // the worst thing that'll happen is that the hit rate for heavily threaded 60 // apps won't be as good as it could be. If you want to burn another 61 // shift+xor you could mix together _all of the %g7 bits to form the hash, 62 // but I think that's excessive. Making the change above changed the 63 // T$ miss rate on SpecJBB (on a 16X system) from about 3% to imperceptible. 64 uintptr_t ix = (int) (((raw_id >> 9) ^ (raw_id >> 20)) % _pd_cache_size); 65 return ix; 66 }