annotate src/os_cpu/linux_x86/vm/threadLS_linux_x86.cpp @ 5318:b5cd7bc05695

Method entry counters: Enable the flag to collect an execution profile of compiled methods and their callers. This allows to, e.g., detect methods that should be inlined because they are called frequently.
author Christian Wimmer <Christian.Wimmer@Oracle.com>
date Fri, 27 Apr 2012 12:56:39 -0700
parents 65dba8692db7
children f34d701e952e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "runtime/threadLocalStorage.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "thread_linux.inline.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Map stack pointer (%esp) to thread pointer for faster TLS access
a61af66fc99e Initial load
duke
parents:
diff changeset
30 //
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Here we use a flat table for better performance. Getting current thread
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // is down to one memory access (read _sp_map[%esp>>12]) in generated code
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // and two in runtime code (-fPIC code needs an extra load for _sp_map).
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // This code assumes stack page is not shared by different threads. It works
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // in 32-bit VM when page size is 4K (or a multiple of 4K, if that matters).
a61af66fc99e Initial load
duke
parents:
diff changeset
37 //
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // Notice that _sp_map is allocated in the bss segment, which is ZFOD
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // (zero-fill-on-demand). While it reserves 4M address space upfront,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // actual memory pages are committed on demand.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 //
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // If an application creates and destroys a lot of threads, usually the
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // stack space freed by a thread will soon get reused by new thread
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // (this is especially true in NPTL or LinuxThreads in fixed-stack mode).
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // No memory page in _sp_map is wasted.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // However, it's still possible that we might end up populating &
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // committing a large fraction of the 4M table over time, but the actual
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // amount of live data in the table could be quite small. The max wastage
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // is less than 4M bytes. If it becomes an issue, we could use madvise()
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // with MADV_DONTNEED to reclaim unused (i.e. all-zero) pages in _sp_map.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // MADV_DONTNEED on Linux keeps the virtual memory mapping, but zaps the
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // physical memory page (i.e. similar to MADV_FREE on Solaris).
a61af66fc99e Initial load
duke
parents:
diff changeset
54
3798
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
55 #if !defined(AMD64) && !defined(MINIMIZE_RAM_USAGE)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 Thread* ThreadLocalStorage::_sp_map[1UL << (SP_BITLENGTH - PAGE_SHIFT)];
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void ThreadLocalStorage::generate_code_for_get_thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // nothing we can do here for user-level thread
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 void ThreadLocalStorage::pd_init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 assert(align_size_down(os::vm_page_size(), PAGE_SIZE) == os::vm_page_size(),
a61af66fc99e Initial load
duke
parents:
diff changeset
64 "page size must be multiple of PAGE_SIZE");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void ThreadLocalStorage::pd_set_thread(Thread* thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 address stack_top = os::current_stack_base();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 size_t stack_size = os::current_stack_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 for (address p = stack_top - stack_size; p < stack_top; p += PAGE_SIZE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // pd_set_thread() is called with non-NULL value when a new thread is
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // created/attached, or with NULL value when a thread is about to exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // If both "thread" and the corresponding _sp_map[] entry are non-NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // they should have the same value. Otherwise it might indicate that the
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // stack page is shared by multiple threads. However, a more likely cause
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // for this assertion to fail is that an attached thread exited without
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // detaching itself from VM, which is a program error and could cause VM
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // to crash.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 assert(thread == NULL || _sp_map[(uintptr_t)p >> PAGE_SHIFT] == NULL ||
a61af66fc99e Initial load
duke
parents:
diff changeset
82 thread == _sp_map[(uintptr_t)p >> PAGE_SHIFT],
a61af66fc99e Initial load
duke
parents:
diff changeset
83 "thread exited without detaching from VM??");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 _sp_map[(uintptr_t)p >> PAGE_SHIFT] = thread;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
3798
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
86 }
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
87 #else
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
88
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
89 void ThreadLocalStorage::generate_code_for_get_thread() {
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
90 // nothing we can do here for user-level thread
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
3798
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
92
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
93 void ThreadLocalStorage::pd_init() {
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
94 }
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
95
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
96 void ThreadLocalStorage::pd_set_thread(Thread* thread) {
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
97 os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
98 }
65dba8692db7 7061197: ThreadLocalStorage sp map table should be optional
jcoomes
parents: 1972
diff changeset
99 #endif // !AMD64 && !MINIMIZE_RAM_USAGE