1 /*
2 * Copyright (c) 1997, 2014, 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 *
432 return addr >= page && addr < (page + os::vm_page_size());
433 }
434
435 static void block_on_serialize_page_trap();
436
437 // threads
438
439 enum ThreadType {
440 vm_thread,
441 cgc_thread, // Concurrent GC thread
442 pgc_thread, // Parallel GC thread
443 java_thread,
444 compiler_thread,
445 watcher_thread,
446 os_thread
447 };
448
449 static bool create_thread(Thread* thread,
450 ThreadType thr_type,
451 size_t stack_size = 0);
452 static bool create_main_thread(JavaThread* thread);
453 static bool create_attached_thread(JavaThread* thread);
454 static void pd_start_thread(Thread* thread);
455 static void start_thread(Thread* thread);
456
457 static void initialize_thread(Thread* thr);
458 static void free_thread(OSThread* osthread);
459
460 // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
461 static intx current_thread_id();
462 static int current_process_id();
463 static int sleep(Thread* thread, jlong ms, bool interruptable);
464 // Short standalone OS sleep suitable for slow path spin loop.
465 // Ignores Thread.interrupt() (so keep it short).
466 // ms = 0, will sleep for the least amount of time allowed by the OS.
467 static void naked_short_sleep(jlong ms);
468 static void infinite_sleep(); // never returns, use with CAUTION
469 static void yield(); // Yields to all threads with same priority
470 enum YieldResult {
471 YIELD_SWITCHED = 1, // caller descheduled, other ready threads exist & ran
472 YIELD_NONEREADY = 0, // No other runnable/ready threads.
|
1 /*
2 * Copyright (c) 1997, 2018, 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 *
432 return addr >= page && addr < (page + os::vm_page_size());
433 }
434
435 static void block_on_serialize_page_trap();
436
437 // threads
438
439 enum ThreadType {
440 vm_thread,
441 cgc_thread, // Concurrent GC thread
442 pgc_thread, // Parallel GC thread
443 java_thread,
444 compiler_thread,
445 watcher_thread,
446 os_thread
447 };
448
449 static bool create_thread(Thread* thread,
450 ThreadType thr_type,
451 size_t stack_size = 0);
452
453 // The "main thread", also known as "starting thread", is the thread
454 // that loads/creates the JVM via JNI_CreateJavaVM.
455 static bool create_main_thread(JavaThread* thread);
456
457 // The primordial thread is the initial process thread. The java
458 // launcher never uses the primordial thread as the main thread, but
459 // applications that host the JVM directly may do so. Some platforms
460 // need special-case handling of the primordial thread if it attaches
461 // to the VM.
462 static bool is_primordial_thread(void)
463 #if defined(_WINDOWS) || defined(BSD)
464 // No way to identify the primordial thread.
465 { return false; }
466 #else
467 ;
468 #endif
469
470 static bool create_attached_thread(JavaThread* thread);
471 static void pd_start_thread(Thread* thread);
472 static void start_thread(Thread* thread);
473
474 static void initialize_thread(Thread* thr);
475 static void free_thread(OSThread* osthread);
476
477 // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
478 static intx current_thread_id();
479 static int current_process_id();
480 static int sleep(Thread* thread, jlong ms, bool interruptable);
481 // Short standalone OS sleep suitable for slow path spin loop.
482 // Ignores Thread.interrupt() (so keep it short).
483 // ms = 0, will sleep for the least amount of time allowed by the OS.
484 static void naked_short_sleep(jlong ms);
485 static void infinite_sleep(); // never returns, use with CAUTION
486 static void yield(); // Yields to all threads with same priority
487 enum YieldResult {
488 YIELD_SWITCHED = 1, // caller descheduled, other ready threads exist & ran
489 YIELD_NONEREADY = 0, // No other runnable/ready threads.
|