os.cpp revision 1562
1472N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A#
include "incls/_precompiled.incl" 0N/A// Fill in buffer with current local time as an ISO-8601 string. 0N/A// E.g., yyyy-mm-ddThh:mm:ss-zzzz. 0N/A// Returns buffer, or NULL if it failed. 0N/A// This would mostly be a call to 0N/A// strftime(...., "%Y-%m-%d" "T" "%H:%M:%S" "%z", ....) 0N/A// except that on Windows the %z behaves badly, so we do it ourselves. 0N/A// Also, people wanted milliseconds on there, 0N/A// and strftime doesn't do milliseconds. 0N/A // Output will be of the form "YYYY-MM-DDThh:mm:ss.mmm+zzzz\0" 0N/A // 12345678901234567890123456789 0N/A "%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d";
0N/A // Sanity check the arguments 0N/A // Get the current time 0N/A // Convert the time value to a tm and timezone variable 0N/A // If daylight savings time is in effect, 0N/A // we are 1 hour East of our time zone 0N/A // Compute the time zone offset. 548N/A // localtime_pd() sets timezone to the difference (in seconds) 0N/A // between UTC and and local time. 0N/A // ISO 8601 says we need the difference between local time and UTC, 548N/A // we change the sign of the localtime_pd() result. 0N/A // Then we have to figure out if if we are ahead (+) or behind (-) UTC. 0N/A // Convert time zone offset seconds to hours and minutes. 0N/A // Print an ISO 8601 date and time stamp into the buffer 0N/A assert(
false,
"possibility of dangling Thread pointer");
0N/A// --------------------- sun.misc.Signal (optional) --------------------- 0N/A// SIGBREAK is sent by the keyboard to query the VM state 0N/A// sigexitnum_pd is a platform-specific special signal used for terminating the Signal thread. 0N/A // FIXME : Currently we have not decieded what should be the status 0N/A // for this java thread blocked here. Once we decide about 0N/A // that we should fix this. 0N/A // Terminate the signal thread 0N/A // Check if the signal is a trigger to start the Attach Listener - in that 0N/A // case don't print stack traces. 0N/A // Print stack traces 0N/A // Any SIGBREAK operations added here should make sure to flush 0N/A // the output stream (e.g. tty->flush()) after output. See 4803766. 0N/A // Each module also prints an extra carriage return after its output. 615N/A true /* need_prologue */);
0N/A // Dispatch the signal to java 0N/A // tty is initialized early so we don't expect it to be null, but 0N/A // if it is we can't risk doing an initialization that might 0N/A // trigger additional out-of-memory conditions 0N/A warning(
"Exception %s occurred dispatching signal %s to handler" 0N/A "- the VM may need to be forcibly terminated",
0N/A // Setup JavaThread for processing signals 0N/A // Initialize thread_oop to put it into the system threadGroup 0N/A // At this point it may be possible that no osthread was created for the 0N/A // JavaThread due to lack of memory. We would have to throw an exception 0N/A // in that case. However, since this must work and we do not allow 0N/A // exceptions anyway, check and abort if this fails. 0N/A "unable to create new native thread");
0N/A// --------------------- loading libraries --------------------- 242N/A // Try to load verify dll first. In 1.3 java dll depends on it and is not 242N/A // always able to find it when the loading executable is outside the JDK. 0N/A // In order to keep working with 1.2 we ignore any loading errors. 242N/A // We may have to wait to fire OnLoad until TLS is initialized. 242N/A // The JNI_OnLoad handling is normally done by method load in 242N/A // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library 242N/A // explicitly so we have to check for JNI_OnLoad as well 0N/A// --------------------- heap allocation utilities --------------------- 0N/A// MallocCushion: size of extra cushion allocated around objects with +UseMallocOnly 0N/A// NB: cannot be debug variable, because these aren't set from the command line until 0N/A// *after* the first few allocs already happened 0N/A#
define paranoid 0
/* only set to 1 if you suspect checking code has bug */ 0N/A // ok, we have four consecutive marker bytes; find start 0N/A // ok, we have four consecutive marker bytes; find end of cushion 0N/A // find block allocated before ptr (not entirely crash-proof) 0N/A // look for cushion in front of prev. block 0N/A // start is bad; mayhave been confused by OS data inbetween objects 0N/A // search one more backwards 0N/A // now find successor block 0N/A // return a valid pointer if size is zero 0N/A // if NULL is returned the calling functions assume out of memory. 0N/A // put size just before data 0N/A // always move the block 0N/A // Copy to new memory if malloc didn't fail 0N/A // tty->print_cr("os::free %p", memblock); 0N/A // Added by detlefs. 0N/A "Thing freed should be malloc result.");
0N/A "Thing freed should be malloc result.");
0N/A /* standard, well-known linear congruential random generator with 0N/A * next_rand = (16807*seed) mod (2**31-1) 0N/A * (1) "Random Number Generators: Good Ones Are Hard to Find", 0N/A * S.K. Park and K.W. Miller, Communications of the ACM 31:10 (Oct 1988), 0N/A * (2) "Two Fast Implementations of the 'Minimal Standard' Random 0N/A * Number Generator", David G. Carta, Comm. ACM 33, 1 (Jan 1990), pp. 87-88. 0N/A const long a =
16807;
0N/A const unsigned long m =
2147483647;
0N/A const long q = m / a;
assert(q ==
127773,
"weird math");
0N/A const long r = m % a;
assert(r ==
2836,
"weird math");
0N/A // compute az=2^31p+q 0N/A // if q overflowed, ignore the overflow and increment q 0N/A // if (p+q) overflowed, ignore the overflow and increment (p+q) 0N/A// The INITIALIZED state is distinguished from the SUSPENDED state because the 0N/A// conditions in which a thread is first started are different from those in which 0N/A// a suspension is resumed. These differences make it hard for us to apply the 0N/A// tougher checks when starting threads that we want to do when resuming them. 0N/A// However, when start_thread is called as a result of Thread.start, on a Java 0N/A// thread, the operation is synchronized on the Java Thread object. So there 0N/A// cannot be a race to start the thread and hence for the thread to exit while 0N/A// we are working on it. Non-Java threads that start Java threads either have 0N/A// to do so in a context in which races are impossible, or should do appropriate 0N/A//--------------------------------------------------------------------------- 0N/A// Helper functions for fatal error handler 0N/A // It's not safe to query number of active processors after crash 0N/A // st->print("(active %d)", os::active_processor_count()); 0N/A // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in 0N/A // Linux. Must be a bug in glibc ? Workaround is to round "t" to int 0N/A // before printf. We lost some precision, but who cares? 0N/A// Looks like all platforms except IA64 can use the same function to check 0N/A// if C stack is walkable beyond current frame. The check for fp() is not 0N/A// necessary on Sparc, but it's harmless. 0N/A // In order to walk native frames on Itanium, we need to access the unwind 0N/A // table, which is inside ELF. We don't want to parse ELF after fatal error, 0N/A // so return true for IA64. If we need to support C stack walking on IA64, 0N/A // this function needs to be moved to CPU specific files, as fp() on IA64 0N/A // is register stack, which grows towards higher memory address. 0N/A // Load up sp, fp, sender sp and sender fp, check for reasonable values. 0N/A // Check usp first, because if that's bad the other accessors may fault 0N/A // on some architectures. Ditto ufp second, etc. 0N/A // sp on amd can be 32 bit aligned. 0N/A // stack grows downwards; if old_fp is below current fp or if the stack 0N/A // frame is too large, either the stack is corrupted or fp is not saved 0N/A // on stack (i.e. on x86, ebp may be used as general register). The stack 0N/A // is not walkable beyond current frame. 0N/A const double m =
2147483647;
0N/A assert(u >=
0.0 && u <=
1.0,
"bad random number!");
0N/A // calculate mean and variance of the random sequence 0N/A// Set up the boot classpath. 0N/A // Scan the format string to determine the length of the actual 0N/A // boot classpath, and handle platform dependencies as well. 0N/A // Create boot classpath from format, substituting separator chars and 0N/A // java home directory. 0N/A // Any modification to the JAR-file list, for the boot classpath must be 0N/A // path class JARs, are stripped for StackMapTable to reduce download size. 1562N/A // ## TEMPORARY hack to keep the legacy launcher working when 1562N/A // ## only the boot module is installed (cf. j.l.ClassLoader) 691N/A * Splits a path, based on its separator, the number of 691N/A * elements is returned back in n. 691N/A * It is the callers responsibility to: 691N/A * a> check the value of n, and n may be 0. 691N/A * b> ignore any empty path elements 691N/A // Get a count of elements to allocate memory 691N/A // do the actual splitting 691N/A // allocate the string and add terminator storage 0N/A // We initialize the serialization page shift count here 0N/A // We assume a cache line size of 64 bytes 0N/A "thread size changed, fix SerializePageShiftCount constant");
0N/A// This method is called from signal handler when SIGSEGV occurs while the current 0N/A// thread tries to store to the "read-only" memory serialize page during state 55N/A // When VMThread is holding the SerializePageLock during modifying the 0N/A // access permission of the memory serialize page, the following call 0N/A // will block until the permission of that page is restored to rw. 0N/A // Generally, it is unsafe to manipulate locks in signal handlers, but in 0N/A // this case, it's OK as the signal is synchronous and we know precisely when 0N/A// Serialize all thread state variables 0N/A // On some platforms such as Solaris & Linux, the time duration of the page 0N/A // permission restoration is observed to be much longer than expected due to 0N/A // scheduler starvation problem etc. To avoid the long synchronization 55N/A // time and expensive page trap spinning, 'SerializePageLock' is used to block 55N/A // the mutator thread if such case is encountered. See bug 6546278 for details. 0N/A// Returns true if the current stack pointer is above the stack shadow 0N/A// pages, false otherwise. 0N/A // Check if we have StackShadowPages above the yellow zone. This parameter 605N/A // is dependent on the depth of the maximum VM call stack possible from 0N/A // the handler for stack overflow. 'instanceof' in the stack overflow 0N/A // handler or a println uses at least 8k stack of VM and native code 0N/A // The very lower end of the stack 0N/A // The largest page size with no fragmentation. 0N/A // The largest page size that satisfies the min_pages requirement. 0N/A#
endif // #ifndef PRODUCT 0N/A// This is the working definition of a server class machine: 0N/A// >= 2 physical CPU's and >=2GB of memory, with some fuzz 0N/A// because the graphics memory (?) sometimes masks physical memory. 0N/A// If you want to change the definition of a server class machine 0N/A// on some OS or platform, e.g., >=4GB on Windohs platforms, 0N/A// then you'll have to parameterize this method based on that state, 0N/A// as was done for logical processors here, or replicate and 0N/A// specialize this method for each platform. (Or fix os to have 0N/A// some inheritance structure and use subclassing. Sigh.) 0N/A// If you want some platform to always or never behave as a server 0N/A// class machine, change the setting of AlwaysActAsServerClassMachine 0N/A// and NeverActAsServerClassMachine in globals*.hpp. 0N/A // First check for the early returns 0N/A // Then actually look at the machine 0N/A // We seem not to get our full complement of memory. 0N/A // We allow some part (1/8?) of the memory to be "missing", 0N/A // based on the sizes of DIMMs, and maybe graphics cards. 0N/A /* Is this a server class machine? */