os.cpp revision 605
2362N/A * Copyright 1997-2008 Sun Microsystems, Inc. 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 2362N/A * published by the Free Software Foundation. 2362N/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. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 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. 0N/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, 0N/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 assert(
false,
"possibility of dangling Thread pointer");
assert(
false,
"Should not happen");
// --------------------- sun.misc.Signal (optional) --------------------- // SIGBREAK is sent by the keyboard to query the VM state // sigexitnum_pd is a platform-specific special signal used for terminating the Signal thread. // FIXME : Currently we have not decieded what should be the status // for this java thread blocked here. Once we decide about // that we should fix this. // Terminate the signal thread // Check if the signal is a trigger to start the Attach Listener - in that // case don't print stack traces. // Any SIGBREAK operations added here should make sure to flush // the output stream (e.g. tty->flush()) after output. See 4803766. // Each module also prints an extra carriage return after its output. // Dispatch the signal to java // tty is initialized early so we don't expect it to be null, but // if it is we can't risk doing an initialization that might // trigger additional out-of-memory conditions warning(
"Exception %s occurred dispatching signal %s to handler" "- the VM may need to be forcibly terminated",
// Setup JavaThread for processing signals // Initialize thread_oop to put it into the system threadGroup // At this point it may be possible that no osthread was created for the // JavaThread due to lack of memory. We would have to throw an exception // in that case. However, since this must work and we do not allow // exceptions anyway, check and abort if this fails. "unable to create new native thread");
// --------------------- loading libraries --------------------- // Try to load verify dll first. In 1.3 java dll depends on it and is not // always able to find it when the loading executable is outside the JDK. // In order to keep working with 1.2 we ignore any loading errors. // We may have to wait to fire OnLoad until TLS is initialized. // The JNI_OnLoad handling is normally done by method load in // java.lang.ClassLoader$NativeLibrary, but the VM loads the base library // explicitly so we have to check for JNI_OnLoad as well // --------------------- heap allocation utilities --------------------- // MallocCushion: size of extra cushion allocated around objects with +UseMallocOnly // NB: cannot be debug variable, because these aren't set from the command line until // *after* the first few allocs already happened #
define paranoid 0
/* only set to 1 if you suspect checking code has bug */ fatal2(
"free: size field of object #%p was overwritten (%lu)",
obj,
size);
// ok, we have four consecutive marker bytes; find start // ok, we have four consecutive marker bytes; find end of cushion // find block allocated before ptr (not entirely crash-proof) tty->
print_cr(
"### cannot find previous block (MallocCushion < 4)");
// look for cushion in front of prev. block // start is bad; mayhave been confused by OS data inbetween objects // search one more backwards // now find successor block fatal(
"memory stomping error");
// return a valid pointer if size is zero // if NULL is returned the calling functions assume out of memory. // put size just before data // Copy to new memory if malloc didn't fail // tty->print_cr("os::free %p", memblock); "Thing freed should be malloc result.");
"Thing freed should be malloc result.");
/* standard, well-known linear congruential random generator with * next_rand = (16807*seed) mod (2**31-1) * (1) "Random Number Generators: Good Ones Are Hard to Find", * S.K. Park and K.W. Miller, Communications of the ACM 31:10 (Oct 1988), * (2) "Two Fast Implementations of the 'Minimal Standard' Random * Number Generator", David G. Carta, Comm. ACM 33, 1 (Jan 1990), pp. 87-88. const unsigned long m =
2147483647;
const long q = m / a;
assert(q ==
127773,
"weird math");
const long r = m % a;
assert(r ==
2836,
"weird math");
unsigned long hi = a * (
long)((
unsigned long)
_rand_seed >>
16);
lo += (
hi &
0x7FFF) <<
16;
// if q overflowed, ignore the overflow and increment q // if (p+q) overflowed, ignore the overflow and increment (p+q) // The INITIALIZED state is distinguished from the SUSPENDED state because the // conditions in which a thread is first started are different from those in which // a suspension is resumed. These differences make it hard for us to apply the // tougher checks when starting threads that we want to do when resuming them. // However, when start_thread is called as a result of Thread.start, on a Java // thread, the operation is synchronized on the Java Thread object. So there // cannot be a race to start the thread and hence for the thread to exit while // we are working on it. Non-Java threads that start Java threads either have // to do so in a context in which races are impossible, or should do appropriate //--------------------------------------------------------------------------- // Helper functions for fatal error handler // It's not safe to query number of active processors after crash // st->print("(active %d)", os::active_processor_count()); // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in // Linux. Must be a bug in glibc ? Workaround is to round "t" to int // before printf. We lost some precision, but who cares? // Looks like all platforms except IA64 can use the same function to check // if C stack is walkable beyond current frame. The check for fp() is not // necessary on Sparc, but it's harmless. // In order to walk native frames on Itanium, we need to access the unwind // table, which is inside ELF. We don't want to parse ELF after fatal error, // so return true for IA64. If we need to support C stack walking on IA64, // this function needs to be moved to CPU specific files, as fp() on IA64 // is register stack, which grows towards higher memory address. // Load up sp, fp, sender sp and sender fp, check for reasonable values. // Check usp first, because if that's bad the other accessors may fault // on some architectures. Ditto ufp second, etc. // sp on amd can be 32 bit aligned. // stack grows downwards; if old_fp is below current fp or if the stack // frame is too large, either the stack is corrupted or fp is not saved // on stack (i.e. on x86, ebp may be used as general register). The stack // is not walkable beyond current frame. const double m =
2147483647;
for (
int k = 0; k <
reps; k++) {
double u = (
double)
num / m;
assert(u >=
0.0 && u <=
1.0,
"bad random number!");
// calculate mean and variance of the random sequence const double eps =
0.0001;
// Set up the boot classpath. // Scan the format string to determine the length of the actual // boot classpath, and handle platform dependencies as well. // Create boot classpath from format, substituting separator chars and // Any modification to the JAR-file list, for the boot classpath must be // path class JARs, are stripped for StackMapTable to reduce download size. // We initialize the serialization page shift count here // We assume a cache line size of 64 bytes "thread size changed, fix SerializePageShiftCount constant");
// This method is called from signal handler when SIGSEGV occurs while the current // thread tries to store to the "read-only" memory serialize page during state tty->
print_cr(
"Block until the serialize page permission restored");
// When VMThread is holding the SerializePageLock during modifying the // access permission of the memory serialize page, the following call // will block until the permission of that page is restored to rw. // Generally, it is unsafe to manipulate locks in signal handlers, but in // this case, it's OK as the signal is synchronous and we know precisely when // Serialize all thread state variables // On some platforms such as Solaris & Linux, the time duration of the page // permission restoration is observed to be much longer than expected due to // scheduler starvation problem etc. To avoid the long synchronization // time and expensive page trap spinning, 'SerializePageLock' is used to block // the mutator thread if such case is encountered. See bug 6546278 for details. // Returns true if the current stack pointer is above the stack shadow // pages, false otherwise. // Check if we have StackShadowPages above the yellow zone. This parameter // is dependent on the depth of the maximum VM call stack possible from // the handler for stack overflow. 'instanceof' in the stack overflow // handler or a println uses at least 8k stack of VM and native code // The very lower end of the stack // The largest page size with no fragmentation. // The largest page size that satisfies the min_pages requirement. #
endif // #ifndef PRODUCT// This is the working definition of a server class machine: // >= 2 physical CPU's and >=2GB of memory, with some fuzz // because the graphics memory (?) sometimes masks physical memory. // If you want to change the definition of a server class machine // on some OS or platform, e.g., >=4GB on Windohs platforms, // then you'll have to parameterize this method based on that state, // as was done for logical processors here, or replicate and // specialize this method for each platform. (Or fix os to have // some inheritance structure and use subclassing. Sigh.) // If you want some platform to always or never behave as a server // class machine, change the setting of AlwaysActAsServerClassMachine // and NeverActAsServerClassMachine in globals*.hpp. // First check for the early returns // Then actually look at the machine // We seem not to get our full complement of memory. // We allow some part (1/8?) of the memory to be "missing", // based on the sizes of DIMMs, and maybe graphics cards. /* Is this a server class machine? */