1 /* 2 * Copyright (c) 1997, 2016, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef _JAVASOFT_JVM_H_ 27 #define _JAVASOFT_JVM_H_ 28 29 #include <sys/stat.h> 30 31 #include "jni.h" 32 #include "jvm_md.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* 39 * This file contains additional functions exported from the VM. 40 * These functions are complementary to the standard JNI support. 41 * There are three parts to this file: 42 * 43 * First, this file contains the VM-related functions needed by native 44 * libraries in the standard Java API. For example, the java.lang.Object 45 * class needs VM-level functions that wait for and notify monitors. 46 * 47 * Second, this file contains the functions and constant definitions 48 * needed by the byte code verifier and class file format checker. 49 * These functions allow the verifier and format checker to be written 50 * in a VM-independent way. 51 * 52 * Third, this file contains various I/O and network operations needed 53 * by the standard Java I/O and network APIs. 54 */ 55 56 /* 57 * Bump the version number when either of the following happens: 58 * 59 * 1. There is a change in JVM_* functions. 60 * 61 * 2. There is a change in the contract between VM and Java classes. 62 * For example, if the VM relies on a new private field in Thread 63 * class. 64 */ 65 66 #define JVM_INTERFACE_VERSION 5 67 68 JNIEXPORT jint JNICALL 69 JVM_GetInterfaceVersion(void); 70 71 /************************************************************************* 72 PART 1: Functions for Native Libraries 73 ************************************************************************/ 74 /* 75 * java.lang.Object 76 */ 77 JNIEXPORT jint JNICALL 78 JVM_IHashCode(JNIEnv *env, jobject obj); 79 80 JNIEXPORT void JNICALL 81 JVM_MonitorWait(JNIEnv *env, jobject obj, jlong ms); 82 83 JNIEXPORT void JNICALL 84 JVM_MonitorNotify(JNIEnv *env, jobject obj); 85 86 JNIEXPORT void JNICALL 87 JVM_MonitorNotifyAll(JNIEnv *env, jobject obj); 88 89 JNIEXPORT jobject JNICALL 90 JVM_Clone(JNIEnv *env, jobject obj); 91 92 /* 93 * java.lang.String 94 */ 95 JNIEXPORT jstring JNICALL 96 JVM_InternString(JNIEnv *env, jstring str); 97 98 /* 99 * java.lang.System 100 */ 101 JNIEXPORT jlong JNICALL 102 JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored); 103 104 JNIEXPORT jlong JNICALL 105 JVM_NanoTime(JNIEnv *env, jclass ignored); 106 107 JNIEXPORT jlong JNICALL 108 JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs); 109 110 JNIEXPORT void JNICALL 111 JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, 112 jobject dst, jint dst_pos, jint length); 113 114 JNIEXPORT jobject JNICALL 115 JVM_InitProperties(JNIEnv *env, jobject p); 116 117 118 /* 119 * java.lang.Runtime 120 */ 121 JNIEXPORT void JNICALL 122 JVM_Halt(jint code); 123 124 JNIEXPORT void JNICALL 125 JVM_GC(void); 126 127 /* Returns the number of real-time milliseconds that have elapsed since the 128 * least-recently-inspected heap object was last inspected by the garbage 129 * collector. 130 * 131 * For simple stop-the-world collectors this value is just the time 132 * since the most recent collection. For generational collectors it is the 133 * time since the oldest generation was most recently collected. Other 134 * collectors are free to return a pessimistic estimate of the elapsed time, or 135 * simply the time since the last full collection was performed. 136 * 137 * Note that in the presence of reference objects, a given object that is no 138 * longer strongly reachable may have to be inspected multiple times before it 139 * can be reclaimed. 140 */ 141 JNIEXPORT jlong JNICALL 142 JVM_MaxObjectInspectionAge(void); 143 144 JNIEXPORT jlong JNICALL 145 JVM_TotalMemory(void); 146 147 JNIEXPORT jlong JNICALL 148 JVM_FreeMemory(void); 149 150 JNIEXPORT jlong JNICALL 151 JVM_MaxMemory(void); 152 153 JNIEXPORT jint JNICALL 154 JVM_ActiveProcessorCount(void); 155 156 JNIEXPORT void * JNICALL 157 JVM_LoadLibrary(const char *name); 158 159 JNIEXPORT void JNICALL 160 JVM_UnloadLibrary(void * handle); 161 162 JNIEXPORT void * JNICALL 163 JVM_FindLibraryEntry(void *handle, const char *name); 164 165 JNIEXPORT jboolean JNICALL 166 JVM_IsSupportedJNIVersion(jint version); 167 168 JNIEXPORT jobjectArray JNICALL 169 JVM_GetVmArguments(JNIEnv *env); 170 171 172 /* 173 * java.lang.Throwable 174 */ 175 JNIEXPORT void JNICALL 176 JVM_FillInStackTrace(JNIEnv *env, jobject throwable); 177 178 /* 179 * java.lang.StackTraceElement 180 */ 181 JNIEXPORT void JNICALL 182 JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable); 183 184 JNIEXPORT void JNICALL 185 JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo); 186 187 /* 188 * java.lang.StackWalker 189 */ 190 enum { 191 JVM_STACKWALK_FILL_CLASS_REFS_ONLY = 0x2, 192 JVM_STACKWALK_GET_CALLER_CLASS = 0x04, 193 JVM_STACKWALK_SHOW_HIDDEN_FRAMES = 0x20, 194 JVM_STACKWALK_FILL_LIVE_STACK_FRAMES = 0x100 195 }; 196 197 JNIEXPORT jobject JNICALL 198 JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode, 199 jint skip_frames, jint frame_count, jint start_index, 200 jobjectArray frames); 201 202 JNIEXPORT jint JNICALL 203 JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor, 204 jint frame_count, jint start_index, 205 jobjectArray frames); 206 207 /* 208 * java.lang.Thread 209 */ 210 JNIEXPORT void JNICALL 211 JVM_StartThread(JNIEnv *env, jobject thread); 212 213 JNIEXPORT void JNICALL 214 JVM_StopThread(JNIEnv *env, jobject thread, jobject exception); 215 216 JNIEXPORT jboolean JNICALL 217 JVM_IsThreadAlive(JNIEnv *env, jobject thread); 218 219 JNIEXPORT void JNICALL 220 JVM_SuspendThread(JNIEnv *env, jobject thread); 221 222 JNIEXPORT void JNICALL 223 JVM_ResumeThread(JNIEnv *env, jobject thread); 224 225 JNIEXPORT void JNICALL 226 JVM_SetThreadPriority(JNIEnv *env, jobject thread, jint prio); 227 228 JNIEXPORT void JNICALL 229 JVM_Yield(JNIEnv *env, jclass threadClass); 230 231 JNIEXPORT void JNICALL 232 JVM_Sleep(JNIEnv *env, jclass threadClass, jlong millis); 233 234 JNIEXPORT jobject JNICALL 235 JVM_CurrentThread(JNIEnv *env, jclass threadClass); 236 237 JNIEXPORT jint JNICALL 238 JVM_CountStackFrames(JNIEnv *env, jobject thread); 239 240 JNIEXPORT void JNICALL 241 JVM_Interrupt(JNIEnv *env, jobject thread); 242 243 JNIEXPORT jboolean JNICALL 244 JVM_IsInterrupted(JNIEnv *env, jobject thread, jboolean clearInterrupted); 245 246 JNIEXPORT jboolean JNICALL 247 JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj); 248 249 JNIEXPORT void JNICALL 250 JVM_DumpAllStacks(JNIEnv *env, jclass unused); 251 252 JNIEXPORT jobjectArray JNICALL 253 JVM_GetAllThreads(JNIEnv *env, jclass dummy); 254 255 JNIEXPORT void JNICALL 256 JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name); 257 258 /* getStackTrace() and getAllStackTraces() method */ 259 JNIEXPORT jobjectArray JNICALL 260 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads); 261 262 /* 263 * java.lang.SecurityManager 264 */ 265 JNIEXPORT jclass JNICALL 266 JVM_CurrentLoadedClass(JNIEnv *env); 267 268 JNIEXPORT jobject JNICALL 269 JVM_CurrentClassLoader(JNIEnv *env); 270 271 JNIEXPORT jobjectArray JNICALL 272 JVM_GetClassContext(JNIEnv *env); 273 274 JNIEXPORT jint JNICALL 275 JVM_ClassDepth(JNIEnv *env, jstring name); 276 277 JNIEXPORT jint JNICALL 278 JVM_ClassLoaderDepth(JNIEnv *env); 279 280 /* 281 * java.lang.Package 282 */ 283 JNIEXPORT jstring JNICALL 284 JVM_GetSystemPackage(JNIEnv *env, jstring name); 285 286 JNIEXPORT jobjectArray JNICALL 287 JVM_GetSystemPackages(JNIEnv *env); 288 289 /* 290 * java.lang.ref.Reference 291 */ 292 JNIEXPORT jobject JNICALL 293 JVM_GetAndClearReferencePendingList(JNIEnv *env); 294 295 JNIEXPORT jboolean JNICALL 296 JVM_HasReferencePendingList(JNIEnv *env); 297 298 JNIEXPORT void JNICALL 299 JVM_WaitForReferencePendingList(JNIEnv *env); 300 301 /* 302 * java.io.ObjectInputStream 303 */ 304 JNIEXPORT jobject JNICALL 305 JVM_LatestUserDefinedLoader(JNIEnv *env); 306 307 /* 308 * java.lang.reflect.Array 309 */ 310 JNIEXPORT jint JNICALL 311 JVM_GetArrayLength(JNIEnv *env, jobject arr); 312 313 JNIEXPORT jobject JNICALL 314 JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index); 315 316 JNIEXPORT jvalue JNICALL 317 JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode); 318 319 JNIEXPORT void JNICALL 320 JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val); 321 322 JNIEXPORT void JNICALL 323 JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, 324 unsigned char vCode); 325 326 JNIEXPORT jobject JNICALL 327 JVM_NewArray(JNIEnv *env, jclass eltClass, jint length); 328 329 JNIEXPORT jobject JNICALL 330 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim); 331 332 /* 333 * java.lang.Class and java.lang.ClassLoader 334 */ 335 336 #define JVM_CALLER_DEPTH -1 337 338 /* 339 * Returns the immediate caller class of the native method invoking 340 * JVM_GetCallerClass. The Method.invoke and other frames due to 341 * reflection machinery are skipped. 342 * 343 * The depth parameter must be -1 (JVM_DEPTH). The caller is expected 344 * to be marked with sun.reflect.CallerSensitive. The JVM will throw 345 * an error if it is not marked propertly. 346 */ 347 JNIEXPORT jclass JNICALL 348 JVM_GetCallerClass(JNIEnv *env, int depth); 349 350 351 /* 352 * Find primitive classes 353 * utf: class name 354 */ 355 JNIEXPORT jclass JNICALL 356 JVM_FindPrimitiveClass(JNIEnv *env, const char *utf); 357 358 359 /* 360 * Find a class from a boot class loader. Returns NULL if class not found. 361 */ 362 JNIEXPORT jclass JNICALL 363 JVM_FindClassFromBootLoader(JNIEnv *env, const char *name); 364 365 /* 366 * Find a class from a given class loader. Throws ClassNotFoundException. 367 * name: name of class 368 * init: whether initialization is done 369 * loader: class loader to look up the class. This may not be the same as the caller's 370 * class loader. 371 * caller: initiating class. The initiating class may be null when a security 372 * manager is not installed. 373 */ 374 JNIEXPORT jclass JNICALL 375 JVM_FindClassFromCaller(JNIEnv *env, const char *name, jboolean init, 376 jobject loader, jclass caller); 377 378 /* 379 * Find a class from a given class. 380 */ 381 JNIEXPORT jclass JNICALL 382 JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, 383 jclass from); 384 385 /* Find a loaded class cached by the VM */ 386 JNIEXPORT jclass JNICALL 387 JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name); 388 389 /* Define a class */ 390 JNIEXPORT jclass JNICALL 391 JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, 392 jsize len, jobject pd); 393 394 /* Define a class with a source (added in JDK1.5) */ 395 JNIEXPORT jclass JNICALL 396 JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, 397 const jbyte *buf, jsize len, jobject pd, 398 const char *source); 399 400 /* 401 * Module support funcions 402 */ 403 404 JNIEXPORT void JNICALL 405 JVM_DefineModule(JNIEnv *env, jobject module, jboolean is_open, jstring version, 406 jstring location, jobjectArray packages); 407 408 JNIEXPORT void JNICALL 409 JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module); 410 411 JNIEXPORT void JNICALL 412 JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject to_module); 413 414 JNIEXPORT void JNICALL 415 JVM_AddModuleExports(JNIEnv *env, jobject from_module, jstring package, jobject to_module); 416 417 JNIEXPORT void JNICALL 418 JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, jstring package); 419 420 JNIEXPORT void JNICALL 421 JVM_AddModuleExportsToAllUnnamed(JNIEnv *env, jobject from_module, jstring package); 422 423 JNIEXPORT void JNICALL 424 JVM_AddModulePackage(JNIEnv* env, jobject module, jstring package); 425 426 JNIEXPORT jobject JNICALL 427 JVM_GetModuleByPackageName(JNIEnv *env, jobject cl, jstring pkg); 428 429 /* 430 * Reflection support functions 431 */ 432 433 JNIEXPORT jstring JNICALL 434 JVM_GetClassName(JNIEnv *env, jclass cls); 435 436 JNIEXPORT jobjectArray JNICALL 437 JVM_GetClassInterfaces(JNIEnv *env, jclass cls); 438 439 JNIEXPORT jboolean JNICALL 440 JVM_IsInterface(JNIEnv *env, jclass cls); 441 442 JNIEXPORT jobjectArray JNICALL 443 JVM_GetClassSigners(JNIEnv *env, jclass cls); 444 445 JNIEXPORT void JNICALL 446 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers); 447 448 JNIEXPORT jobject JNICALL 449 JVM_GetProtectionDomain(JNIEnv *env, jclass cls); 450 451 JNIEXPORT jboolean JNICALL 452 JVM_IsArrayClass(JNIEnv *env, jclass cls); 453 454 JNIEXPORT jboolean JNICALL 455 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls); 456 457 JNIEXPORT jint JNICALL 458 JVM_GetClassModifiers(JNIEnv *env, jclass cls); 459 460 JNIEXPORT jobjectArray JNICALL 461 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass); 462 463 JNIEXPORT jclass JNICALL 464 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass); 465 466 JNIEXPORT jstring JNICALL 467 JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass); 468 469 /* Generics support (JDK 1.5) */ 470 JNIEXPORT jstring JNICALL 471 JVM_GetClassSignature(JNIEnv *env, jclass cls); 472 473 /* Annotations support (JDK 1.5) */ 474 JNIEXPORT jbyteArray JNICALL 475 JVM_GetClassAnnotations(JNIEnv *env, jclass cls); 476 477 /* Type use annotations support (JDK 1.8) */ 478 479 JNIEXPORT jbyteArray JNICALL 480 JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); 481 482 JNIEXPORT jbyteArray JNICALL 483 JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field); 484 485 JNIEXPORT jbyteArray JNICALL 486 JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method); 487 488 /* 489 * New (JDK 1.4) reflection implementation 490 */ 491 492 JNIEXPORT jobjectArray JNICALL 493 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly); 494 495 JNIEXPORT jobjectArray JNICALL 496 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly); 497 498 JNIEXPORT jobjectArray JNICALL 499 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly); 500 501 /* Differs from JVM_GetClassModifiers in treatment of inner classes. 502 This returns the access flags for the class as specified in the 503 class file rather than searching the InnerClasses attribute (if 504 present) to find the source-level access flags. Only the values of 505 the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be 506 valid. */ 507 JNIEXPORT jint JNICALL 508 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls); 509 510 /* The following two reflection routines are still needed due to startup time issues */ 511 /* 512 * java.lang.reflect.Method 513 */ 514 JNIEXPORT jobject JNICALL 515 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0); 516 517 /* 518 * java.lang.reflect.Constructor 519 */ 520 JNIEXPORT jobject JNICALL 521 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0); 522 523 /* 524 * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5) 525 */ 526 527 JNIEXPORT jobject JNICALL 528 JVM_GetClassConstantPool(JNIEnv *env, jclass cls); 529 530 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize 531 (JNIEnv *env, jobject unused, jobject jcpool); 532 533 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt 534 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 535 536 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded 537 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 538 539 JNIEXPORT jint JNICALL JVM_ConstantPoolGetClassRefIndexAt 540 (JNIEnv *env, jobject obj, jobject unused, jint index); 541 542 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt 543 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 544 545 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded 546 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 547 548 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt 549 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 550 551 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded 552 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 553 554 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt 555 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 556 557 JNIEXPORT jint JNICALL JVM_ConstantPoolGetNameAndTypeRefIndexAt 558 (JNIEnv *env, jobject obj, jobject unused, jint index); 559 560 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetNameAndTypeRefInfoAt 561 (JNIEnv *env, jobject obj, jobject unused, jint index); 562 563 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt 564 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 565 566 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt 567 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 568 569 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt 570 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 571 572 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt 573 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 574 575 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt 576 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 577 578 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At 579 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 580 581 JNIEXPORT jbyte JNICALL JVM_ConstantPoolGetTagAt 582 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 583 584 /* 585 * Parameter reflection 586 */ 587 588 JNIEXPORT jobjectArray JNICALL 589 JVM_GetMethodParameters(JNIEnv *env, jobject method); 590 591 /* 592 * java.security.* 593 */ 594 595 JNIEXPORT jobject JNICALL 596 JVM_DoPrivileged(JNIEnv *env, jclass cls, 597 jobject action, jobject context, jboolean wrapException); 598 599 JNIEXPORT jobject JNICALL 600 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); 601 602 JNIEXPORT jobject JNICALL 603 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls); 604 605 /* 606 * Signal support, used to implement the shutdown sequence. Every VM must 607 * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts 608 * (^C) and the latter for external termination (kill, system shutdown, etc.). 609 * Other platform-dependent signal values may also be supported. 610 */ 611 612 JNIEXPORT void * JNICALL 613 JVM_RegisterSignal(jint sig, void *handler); 614 615 JNIEXPORT jboolean JNICALL 616 JVM_RaiseSignal(jint sig); 617 618 JNIEXPORT jint JNICALL 619 JVM_FindSignal(const char *name); 620 621 /* 622 * Retrieve the assertion directives for the specified class. 623 */ 624 JNIEXPORT jboolean JNICALL 625 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls); 626 627 /* 628 * Retrieve the assertion directives from the VM. 629 */ 630 JNIEXPORT jobject JNICALL 631 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused); 632 633 /* 634 * java.util.concurrent.atomic.AtomicLong 635 */ 636 JNIEXPORT jboolean JNICALL 637 JVM_SupportsCX8(void); 638 639 /* 640 * com.sun.dtrace.jsdt support 641 */ 642 643 #define JVM_TRACING_DTRACE_VERSION 1 644 645 /* 646 * Structure to pass one probe description to JVM 647 */ 648 typedef struct { 649 jmethodID method; 650 jstring function; 651 jstring name; 652 void* reserved[4]; // for future use 653 } JVM_DTraceProbe; 654 655 /** 656 * Encapsulates the stability ratings for a DTrace provider field 657 */ 658 typedef struct { 659 jint nameStability; 660 jint dataStability; 661 jint dependencyClass; 662 } JVM_DTraceInterfaceAttributes; 663 664 /* 665 * Structure to pass one provider description to JVM 666 */ 667 typedef struct { 668 jstring name; 669 JVM_DTraceProbe* probes; 670 jint probe_count; 671 JVM_DTraceInterfaceAttributes providerAttributes; 672 JVM_DTraceInterfaceAttributes moduleAttributes; 673 JVM_DTraceInterfaceAttributes functionAttributes; 674 JVM_DTraceInterfaceAttributes nameAttributes; 675 JVM_DTraceInterfaceAttributes argsAttributes; 676 void* reserved[4]; // for future use 677 } JVM_DTraceProvider; 678 679 /* 680 * Get the version number the JVM was built with 681 */ 682 JNIEXPORT jint JNICALL 683 JVM_DTraceGetVersion(JNIEnv* env); 684 685 /* 686 * Register new probe with given signature, return global handle 687 * 688 * The version passed in is the version that the library code was 689 * built with. 690 */ 691 JNIEXPORT jlong JNICALL 692 JVM_DTraceActivate(JNIEnv* env, jint version, jstring module_name, 693 jint providers_count, JVM_DTraceProvider* providers); 694 695 /* 696 * Check JSDT probe 697 */ 698 JNIEXPORT jboolean JNICALL 699 JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method); 700 701 /* 702 * Destroy custom DOF 703 */ 704 JNIEXPORT void JNICALL 705 JVM_DTraceDispose(JNIEnv* env, jlong activation_handle); 706 707 /* 708 * Check to see if DTrace is supported by OS 709 */ 710 JNIEXPORT jboolean JNICALL 711 JVM_DTraceIsSupported(JNIEnv* env); 712 713 /************************************************************************* 714 PART 2: Support for the Verifier and Class File Format Checker 715 ************************************************************************/ 716 /* 717 * Return the class name in UTF format. The result is valid 718 * until JVM_ReleaseUTf is called. 719 * 720 * The caller must treat the string as a constant and not modify it 721 * in any way. 722 */ 723 JNIEXPORT const char * JNICALL 724 JVM_GetClassNameUTF(JNIEnv *env, jclass cb); 725 726 /* 727 * Returns the constant pool types in the buffer provided by "types." 728 */ 729 JNIEXPORT void JNICALL 730 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types); 731 732 /* 733 * Returns the number of Constant Pool entries. 734 */ 735 JNIEXPORT jint JNICALL 736 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb); 737 738 /* 739 * Returns the number of *declared* fields or methods. 740 */ 741 JNIEXPORT jint JNICALL 742 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb); 743 744 JNIEXPORT jint JNICALL 745 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb); 746 747 /* 748 * Returns the CP indexes of exceptions raised by a given method. 749 * Places the result in the given buffer. 750 * 751 * The method is identified by method_index. 752 */ 753 JNIEXPORT void JNICALL 754 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index, 755 unsigned short *exceptions); 756 /* 757 * Returns the number of exceptions raised by a given method. 758 * The method is identified by method_index. 759 */ 760 JNIEXPORT jint JNICALL 761 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index); 762 763 /* 764 * Returns the byte code sequence of a given method. 765 * Places the result in the given buffer. 766 * 767 * The method is identified by method_index. 768 */ 769 JNIEXPORT void JNICALL 770 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index, 771 unsigned char *code); 772 773 /* 774 * Returns the length of the byte code sequence of a given method. 775 * The method is identified by method_index. 776 */ 777 JNIEXPORT jint JNICALL 778 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index); 779 780 /* 781 * A structure used to a capture exception table entry in a Java method. 782 */ 783 typedef struct { 784 jint start_pc; 785 jint end_pc; 786 jint handler_pc; 787 jint catchType; 788 } JVM_ExceptionTableEntryType; 789 790 /* 791 * Returns the exception table entry at entry_index of a given method. 792 * Places the result in the given buffer. 793 * 794 * The method is identified by method_index. 795 */ 796 JNIEXPORT void JNICALL 797 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index, 798 jint entry_index, 799 JVM_ExceptionTableEntryType *entry); 800 801 /* 802 * Returns the length of the exception table of a given method. 803 * The method is identified by method_index. 804 */ 805 JNIEXPORT jint JNICALL 806 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index); 807 808 /* 809 * Returns the modifiers of a given field. 810 * The field is identified by field_index. 811 */ 812 JNIEXPORT jint JNICALL 813 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index); 814 815 /* 816 * Returns the modifiers of a given method. 817 * The method is identified by method_index. 818 */ 819 JNIEXPORT jint JNICALL 820 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index); 821 822 /* 823 * Returns the number of local variables of a given method. 824 * The method is identified by method_index. 825 */ 826 JNIEXPORT jint JNICALL 827 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index); 828 829 /* 830 * Returns the number of arguments (including this pointer) of a given method. 831 * The method is identified by method_index. 832 */ 833 JNIEXPORT jint JNICALL 834 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index); 835 836 /* 837 * Returns the maximum amount of stack (in words) used by a given method. 838 * The method is identified by method_index. 839 */ 840 JNIEXPORT jint JNICALL 841 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index); 842 843 /* 844 * Is a given method a constructor. 845 * The method is identified by method_index. 846 */ 847 JNIEXPORT jboolean JNICALL 848 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index); 849 850 /* 851 * Is the given method generated by the VM. 852 * The method is identified by method_index. 853 */ 854 JNIEXPORT jboolean JNICALL 855 JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, int index); 856 857 /* 858 * Returns the name of a given method in UTF format. 859 * The result remains valid until JVM_ReleaseUTF is called. 860 * 861 * The caller must treat the string as a constant and not modify it 862 * in any way. 863 */ 864 JNIEXPORT const char * JNICALL 865 JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index); 866 867 /* 868 * Returns the signature of a given method in UTF format. 869 * The result remains valid until JVM_ReleaseUTF is called. 870 * 871 * The caller must treat the string as a constant and not modify it 872 * in any way. 873 */ 874 JNIEXPORT const char * JNICALL 875 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index); 876 877 /* 878 * Returns the name of the field referred to at a given constant pool 879 * index. 880 * 881 * The result is in UTF format and remains valid until JVM_ReleaseUTF 882 * is called. 883 * 884 * The caller must treat the string as a constant and not modify it 885 * in any way. 886 */ 887 JNIEXPORT const char * JNICALL 888 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index); 889 890 /* 891 * Returns the name of the method referred to at a given constant pool 892 * index. 893 * 894 * The result is in UTF format and remains valid until JVM_ReleaseUTF 895 * is called. 896 * 897 * The caller must treat the string as a constant and not modify it 898 * in any way. 899 */ 900 JNIEXPORT const char * JNICALL 901 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index); 902 903 /* 904 * Returns the signature of the method referred to at a given constant pool 905 * index. 906 * 907 * The result is in UTF format and remains valid until JVM_ReleaseUTF 908 * is called. 909 * 910 * The caller must treat the string as a constant and not modify it 911 * in any way. 912 */ 913 JNIEXPORT const char * JNICALL 914 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index); 915 916 /* 917 * Returns the signature of the field referred to at a given constant pool 918 * index. 919 * 920 * The result is in UTF format and remains valid until JVM_ReleaseUTF 921 * is called. 922 * 923 * The caller must treat the string as a constant and not modify it 924 * in any way. 925 */ 926 JNIEXPORT const char * JNICALL 927 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index); 928 929 /* 930 * Returns the class name referred to at a given constant pool index. 931 * 932 * The result is in UTF format and remains valid until JVM_ReleaseUTF 933 * is called. 934 * 935 * The caller must treat the string as a constant and not modify it 936 * in any way. 937 */ 938 JNIEXPORT const char * JNICALL 939 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index); 940 941 /* 942 * Returns the class name referred to at a given constant pool index. 943 * 944 * The constant pool entry must refer to a CONSTANT_Fieldref. 945 * 946 * The result is in UTF format and remains valid until JVM_ReleaseUTF 947 * is called. 948 * 949 * The caller must treat the string as a constant and not modify it 950 * in any way. 951 */ 952 JNIEXPORT const char * JNICALL 953 JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index); 954 955 /* 956 * Returns the class name referred to at a given constant pool index. 957 * 958 * The constant pool entry must refer to CONSTANT_Methodref or 959 * CONSTANT_InterfaceMethodref. 960 * 961 * The result is in UTF format and remains valid until JVM_ReleaseUTF 962 * is called. 963 * 964 * The caller must treat the string as a constant and not modify it 965 * in any way. 966 */ 967 JNIEXPORT const char * JNICALL 968 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index); 969 970 /* 971 * Returns the modifiers of a field in calledClass. The field is 972 * referred to in class cb at constant pool entry index. 973 * 974 * The caller must treat the string as a constant and not modify it 975 * in any way. 976 * 977 * Returns -1 if the field does not exist in calledClass. 978 */ 979 JNIEXPORT jint JNICALL 980 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 981 982 /* 983 * Returns the modifiers of a method in calledClass. The method is 984 * referred to in class cb at constant pool entry index. 985 * 986 * Returns -1 if the method does not exist in calledClass. 987 */ 988 JNIEXPORT jint JNICALL 989 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 990 991 /* 992 * Releases the UTF string obtained from the VM. 993 */ 994 JNIEXPORT void JNICALL 995 JVM_ReleaseUTF(const char *utf); 996 997 /* 998 * Compare if two classes are in the same package. 999 */ 1000 JNIEXPORT jboolean JNICALL 1001 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2); 1002 1003 /* Get classfile constants */ 1004 #include "classfile_constants.h" 1005 1006 /* 1007 * A function defined by the byte-code verifier and called by the VM. 1008 * This is not a function implemented in the VM. 1009 * 1010 * Returns JNI_FALSE if verification fails. A detailed error message 1011 * will be places in msg_buf, whose length is specified by buf_len. 1012 */ 1013 typedef jboolean (*verifier_fn_t)(JNIEnv *env, 1014 jclass cb, 1015 char * msg_buf, 1016 jint buf_len); 1017 1018 1019 /* 1020 * Support for a VM-independent class format checker. 1021 */ 1022 typedef struct { 1023 unsigned long code; /* byte code */ 1024 unsigned long excs; /* exceptions */ 1025 unsigned long etab; /* catch table */ 1026 unsigned long lnum; /* line number */ 1027 unsigned long lvar; /* local vars */ 1028 } method_size_info; 1029 1030 typedef struct { 1031 unsigned int constants; /* constant pool */ 1032 unsigned int fields; 1033 unsigned int methods; 1034 unsigned int interfaces; 1035 unsigned int fields2; /* number of static 2-word fields */ 1036 unsigned int innerclasses; /* # of records in InnerClasses attr */ 1037 1038 method_size_info clinit; /* memory used in clinit */ 1039 method_size_info main; /* used everywhere else */ 1040 } class_size_info; 1041 1042 /* 1043 * Functions defined in libjava.so to perform string conversions. 1044 * 1045 */ 1046 1047 typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str); 1048 1049 typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b); 1050 1051 /* This is the function defined in libjava.so that performs class 1052 * format checks. This functions fills in size information about 1053 * the class file and returns: 1054 * 1055 * 0: good 1056 * -1: out of memory 1057 * -2: bad format 1058 * -3: unsupported version 1059 * -4: bad class name 1060 */ 1061 1062 typedef jint (*check_format_fn_t)(char *class_name, 1063 unsigned char *data, 1064 unsigned int data_size, 1065 class_size_info *class_size, 1066 char *message_buffer, 1067 jint buffer_length, 1068 jboolean measure_only, 1069 jboolean check_relaxed); 1070 1071 #define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \ 1072 JVM_ACC_FINAL | \ 1073 JVM_ACC_SUPER | \ 1074 JVM_ACC_INTERFACE | \ 1075 JVM_ACC_ABSTRACT | \ 1076 JVM_ACC_ANNOTATION | \ 1077 JVM_ACC_ENUM | \ 1078 JVM_ACC_SYNTHETIC) 1079 1080 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \ 1081 JVM_ACC_PRIVATE | \ 1082 JVM_ACC_PROTECTED | \ 1083 JVM_ACC_STATIC | \ 1084 JVM_ACC_FINAL | \ 1085 JVM_ACC_VOLATILE | \ 1086 JVM_ACC_TRANSIENT | \ 1087 JVM_ACC_ENUM | \ 1088 JVM_ACC_SYNTHETIC) 1089 1090 #define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \ 1091 JVM_ACC_PRIVATE | \ 1092 JVM_ACC_PROTECTED | \ 1093 JVM_ACC_STATIC | \ 1094 JVM_ACC_FINAL | \ 1095 JVM_ACC_SYNCHRONIZED | \ 1096 JVM_ACC_BRIDGE | \ 1097 JVM_ACC_VARARGS | \ 1098 JVM_ACC_NATIVE | \ 1099 JVM_ACC_ABSTRACT | \ 1100 JVM_ACC_STRICT | \ 1101 JVM_ACC_SYNTHETIC) 1102 1103 /* 1104 * This is the function defined in libjava.so to perform path 1105 * canonicalization. VM call this function before opening jar files 1106 * to load system classes. 1107 * 1108 */ 1109 1110 typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len); 1111 1112 /************************************************************************* 1113 PART 3: I/O and Network Support 1114 ************************************************************************/ 1115 1116 /* 1117 * Convert a pathname into native format. This function does syntactic 1118 * cleanup, such as removing redundant separator characters. It modifies 1119 * the given pathname string in place. 1120 */ 1121 JNIEXPORT char * JNICALL 1122 JVM_NativePath(char *); 1123 1124 /* 1125 * The standard printing functions supported by the Java VM. (Should they 1126 * be renamed to JVM_* in the future? 1127 */ 1128 1129 /* 1130 * BE CAREFUL! The following functions do not implement the 1131 * full feature set of standard C printf formats. 1132 */ 1133 int 1134 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args); 1135 1136 int 1137 jio_snprintf(char *str, size_t count, const char *fmt, ...); 1138 1139 int 1140 jio_fprintf(FILE *, const char *fmt, ...); 1141 1142 int 1143 jio_vfprintf(FILE *, const char *fmt, va_list args); 1144 1145 1146 JNIEXPORT void * JNICALL 1147 JVM_RawMonitorCreate(void); 1148 1149 JNIEXPORT void JNICALL 1150 JVM_RawMonitorDestroy(void *mon); 1151 1152 JNIEXPORT jint JNICALL 1153 JVM_RawMonitorEnter(void *mon); 1154 1155 JNIEXPORT void JNICALL 1156 JVM_RawMonitorExit(void *mon); 1157 1158 /* 1159 * java.lang.management support 1160 */ 1161 JNIEXPORT void* JNICALL 1162 JVM_GetManagement(jint version); 1163 1164 /* 1165 * com.sun.tools.attach.VirtualMachine support 1166 * 1167 * Initialize the agent properties with the properties maintained in the VM. 1168 */ 1169 JNIEXPORT jobject JNICALL 1170 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props); 1171 1172 JNIEXPORT jstring JNICALL 1173 JVM_GetTemporaryDirectory(JNIEnv *env); 1174 1175 /* Generics reflection support. 1176 * 1177 * Returns information about the given class's EnclosingMethod 1178 * attribute, if present, or null if the class had no enclosing 1179 * method. 1180 * 1181 * If non-null, the returned array contains three elements. Element 0 1182 * is the java.lang.Class of which the enclosing method is a member, 1183 * and elements 1 and 2 are the java.lang.Strings for the enclosing 1184 * method's name and descriptor, respectively. 1185 */ 1186 JNIEXPORT jobjectArray JNICALL 1187 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass); 1188 1189 /* ========================================================================= 1190 * The following defines a private JVM interface that the JDK can query 1191 * for the JVM version and capabilities. sun.misc.Version defines 1192 * the methods for getting the VM version and its capabilities. 1193 * 1194 * When a new bit is added, the following should be updated to provide 1195 * access to the new capability: 1196 * HS: JVM_GetVersionInfo and Abstract_VM_Version class 1197 * SDK: Version class 1198 * 1199 * Similary, a private JDK interface JDK_GetVersionInfo0 is defined for 1200 * JVM to query for the JDK version and capabilities. 1201 * 1202 * When a new bit is added, the following should be updated to provide 1203 * access to the new capability: 1204 * HS: JDK_Version class 1205 * SDK: JDK_GetVersionInfo0 1206 * 1207 * ========================================================================== 1208 */ 1209 typedef struct { 1210 unsigned int jvm_version; /* Encoded $VNUM as specified by JEP-223 */ 1211 unsigned int patch_version : 8; /* JEP-223 patch version */ 1212 unsigned int reserved3 : 8; 1213 unsigned int reserved1 : 16; 1214 unsigned int reserved2; 1215 1216 /* The following bits represents JVM supports that JDK has dependency on. 1217 * JDK can use these bits to determine which JVM version 1218 * and support it has to maintain runtime compatibility. 1219 * 1220 * When a new bit is added in a minor or update release, make sure 1221 * the new bit is also added in the main/baseline. 1222 */ 1223 unsigned int is_attach_supported : 1; 1224 unsigned int : 31; 1225 unsigned int : 32; 1226 unsigned int : 32; 1227 } jvm_version_info; 1228 1229 #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1230 #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1231 #define JVM_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) 1232 #define JVM_VERSION_BUILD(version) ((version & 0x000000FF)) 1233 1234 JNIEXPORT void JNICALL 1235 JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size); 1236 1237 typedef struct { 1238 unsigned int jdk_version; /* Encoded $VNUM as specified by JEP-223 */ 1239 unsigned int patch_version : 8; /* JEP-223 patch version */ 1240 unsigned int reserved3 : 8; 1241 unsigned int reserved1 : 16; 1242 unsigned int reserved2; 1243 1244 /* The following bits represents new JDK supports that VM has dependency on. 1245 * VM implementation can use these bits to determine which JDK version 1246 * and support it has to maintain runtime compatibility. 1247 * 1248 * When a new bit is added in a minor or update release, make sure 1249 * the new bit is also added in the main/baseline. 1250 */ 1251 unsigned int thread_park_blocker : 1; 1252 unsigned int post_vm_init_hook_enabled : 1; 1253 unsigned int pending_list_uses_discovered_field : 1; 1254 unsigned int : 29; 1255 unsigned int : 32; 1256 unsigned int : 32; 1257 } jdk_version_info; 1258 1259 #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1260 #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1261 #define JDK_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) 1262 #define JDK_VERSION_BUILD(version) ((version & 0x000000FF)) 1263 1264 /* 1265 * This is the function JDK_GetVersionInfo0 defined in libjava.so 1266 * that is dynamically looked up by JVM. 1267 */ 1268 typedef void (*jdk_version_info_fn_t)(jdk_version_info* info, size_t info_size); 1269 1270 /* 1271 * This structure is used by the launcher to get the default thread 1272 * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a 1273 * version of 1.1. As it is not supported otherwise, it has been removed 1274 * from jni.h 1275 */ 1276 typedef struct JDK1_1InitArgs { 1277 jint version; 1278 1279 char **properties; 1280 jint checkSource; 1281 jint nativeStackSize; 1282 jint javaStackSize; 1283 jint minHeapSize; 1284 jint maxHeapSize; 1285 jint verifyMode; 1286 char *classpath; 1287 1288 jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args); 1289 void (JNICALL *exit)(jint code); 1290 void (JNICALL *abort)(void); 1291 1292 jint enableClassGC; 1293 jint enableVerboseGC; 1294 jint disableAsyncGC; 1295 jint verbose; 1296 jboolean debugging; 1297 jint debugPort; 1298 } JDK1_1InitArgs; 1299 1300 1301 #ifdef __cplusplus 1302 } /* extern "C" */ 1303 1304 #endif /* __cplusplus */ 1305 1306 #endif /* !_JAVASOFT_JVM_H_ */