Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: src/platform-posix.cc

Issue 23641009: Refactor and cleanup VirtualMemory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nits. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Mac OS X requires all these to install so we can assume they are present. 84 // Mac OS X requires all these to install so we can assume they are present.
85 // These constants are defined by the CPUid instructions. 85 // These constants are defined by the CPUid instructions.
86 const uint64_t one = 1; 86 const uint64_t one = 1;
87 return (one << SSE2) | (one << CMOV); 87 return (one << SSE2) | (one << CMOV);
88 #else 88 #else
89 return 0; // Nothing special about the other systems. 89 return 0; // Nothing special about the other systems.
90 #endif 90 #endif
91 } 91 }
92 92
93 93
94 // Maximum size of the virtual memory. 0 means there is no artificial
95 // limit.
96
97 intptr_t OS::MaxVirtualMemory() {
98 struct rlimit limit;
99 int result = getrlimit(RLIMIT_DATA, &limit);
100 if (result != 0) return 0;
101 return limit.rlim_cur;
102 }
103
104
105 int OS::ActivationFrameAlignment() { 94 int OS::ActivationFrameAlignment() {
106 #if V8_TARGET_ARCH_ARM 95 #if V8_TARGET_ARCH_ARM
107 // On EABI ARM targets this is required for fp correctness in the 96 // On EABI ARM targets this is required for fp correctness in the
108 // runtime system. 97 // runtime system.
109 return 8; 98 return 8;
110 #elif V8_TARGET_ARCH_MIPS 99 #elif V8_TARGET_ARCH_MIPS
111 return 8; 100 return 8;
112 #else 101 #else
113 // Otherwise we just assume 16 byte alignment, i.e.: 102 // Otherwise we just assume 16 byte alignment, i.e.:
114 // - With gcc 4.4 the tree vectorization optimizer can generate code 103 // - With gcc 4.4 the tree vectorization optimizer can generate code
115 // that requires 16 byte alignment such as movdqa on x86. 104 // that requires 16 byte alignment such as movdqa on x86.
116 // - Mac OS X and Solaris (64-bit) activation frames must be 16 byte-aligned; 105 // - Mac OS X and Solaris (64-bit) activation frames must be 16 byte-aligned;
117 // see "Mac OS X ABI Function Call Guide" 106 // see "Mac OS X ABI Function Call Guide"
118 return 16; 107 return 16;
119 #endif 108 #endif
120 } 109 }
121 110
122 111
123 intptr_t OS::CommitPageSize() {
124 static intptr_t page_size = getpagesize();
125 return page_size;
126 }
127
128
129 void OS::Free(void* address, const size_t size) {
130 // TODO(1240712): munmap has a return value which is ignored here.
131 int result = munmap(address, size);
132 USE(result);
133 ASSERT(result == 0);
134 }
135
136
137 // Get rid of writable permission on code allocations.
138 void OS::ProtectCode(void* address, const size_t size) {
139 #if defined(__CYGWIN__)
140 DWORD old_protect;
141 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
142 #elif defined(__native_client__)
143 // The Native Client port of V8 uses an interpreter, so
144 // code pages don't need PROT_EXEC.
145 mprotect(address, size, PROT_READ);
146 #else
147 mprotect(address, size, PROT_READ | PROT_EXEC);
148 #endif
149 }
150
151
152 // Create guard pages.
153 void OS::Guard(void* address, const size_t size) {
154 #if defined(__CYGWIN__)
155 DWORD oldprotect;
156 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect);
157 #else
158 mprotect(address, size, PROT_NONE);
159 #endif
160 }
161
162
163 void* OS::GetRandomMmapAddr() {
164 #if defined(__native_client__)
165 // TODO(bradchen): restore randomization once Native Client gets
166 // smarter about using mmap address hints.
167 // See http://code.google.com/p/nativeclient/issues/3341
168 return NULL;
169 #endif
170 Isolate* isolate = Isolate::UncheckedCurrent();
171 // Note that the current isolate isn't set up in a call path via
172 // CpuFeatures::Probe. We don't care about randomization in this case because
173 // the code page is immediately freed.
174 if (isolate != NULL) {
175 uintptr_t raw_addr;
176 isolate->random_number_generator()->NextBytes(&raw_addr, sizeof(raw_addr));
177 #if V8_TARGET_ARCH_X64
178 // Currently available CPUs have 48 bits of virtual addressing. Truncate
179 // the hint address to 46 bits to give the kernel a fighting chance of
180 // fulfilling our placement request.
181 raw_addr &= V8_UINT64_C(0x3ffffffff000);
182 #else
183 raw_addr &= 0x3ffff000;
184
185 # ifdef __sun
186 // For our Solaris/illumos mmap hint, we pick a random address in the bottom
187 // half of the top half of the address space (that is, the third quarter).
188 // Because we do not MAP_FIXED, this will be treated only as a hint -- the
189 // system will not fail to mmap() because something else happens to already
190 // be mapped at our random address. We deliberately set the hint high enough
191 // to get well above the system's break (that is, the heap); Solaris and
192 // illumos will try the hint and if that fails allocate as if there were
193 // no hint at all. The high hint prevents the break from getting hemmed in
194 // at low values, ceding half of the address space to the system heap.
195 raw_addr += 0x80000000;
196 # else
197 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a
198 // variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos
199 // 10.6 and 10.7.
200 raw_addr += 0x20000000;
201 # endif
202 #endif
203 return reinterpret_cast<void*>(raw_addr);
204 }
205 return NULL;
206 }
207
208
209 size_t OS::AllocateAlignment() {
210 return getpagesize();
211 }
212
213
214 void OS::Sleep(int milliseconds) { 112 void OS::Sleep(int milliseconds) {
215 useconds_t ms = static_cast<useconds_t>(milliseconds); 113 useconds_t ms = static_cast<useconds_t>(milliseconds);
216 usleep(1000 * ms); 114 usleep(1000 * ms);
217 } 115 }
218 116
219 117
220 void OS::Abort() { 118 void OS::Abort() {
221 // Redirect to std abort to signal abnormal program termination. 119 // Redirect to std abort to signal abnormal program termination.
222 if (FLAG_break_on_abort) { 120 if (FLAG_break_on_abort) {
223 DebugBreak(); 121 DebugBreak();
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 629
732 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 630 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
733 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 631 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
734 int result = pthread_setspecific(pthread_key, value); 632 int result = pthread_setspecific(pthread_key, value);
735 ASSERT_EQ(0, result); 633 ASSERT_EQ(0, result);
736 USE(result); 634 USE(result);
737 } 635 }
738 636
739 637
740 } } // namespace v8::internal 638 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-openbsd.cc ('k') | src/platform-solaris.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698