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, const char* const* packages, jsize num_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, const char* package, jobject to_module); 416 417 JNIEXPORT void JNICALL 418 JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, const char* package); 419 420 JNIEXPORT void JNICALL 421 JVM_AddModuleExportsToAllUnnamed(JNIEnv *env, jobject from_module, const char* package); 422 423 JNIEXPORT void JNICALL 424 JVM_AddModulePackage(JNIEnv* env, jobject module, const char* package); 425 426 /* 427 * Reflection support functions 428 */ 429 430 JNIEXPORT jstring JNICALL 431 JVM_GetClassName(JNIEnv *env, jclass cls); 432 433 JNIEXPORT jobjectArray JNICALL 434 JVM_GetClassInterfaces(JNIEnv *env, jclass cls); 435 436 JNIEXPORT jboolean JNICALL 437 JVM_IsInterface(JNIEnv *env, jclass cls); 438 439 JNIEXPORT jobjectArray JNICALL 440 JVM_GetClassSigners(JNIEnv *env, jclass cls); 441 442 JNIEXPORT void JNICALL 443 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers); 444 445 JNIEXPORT jobject JNICALL 446 JVM_GetProtectionDomain(JNIEnv *env, jclass cls); 447 448 JNIEXPORT jboolean JNICALL 449 JVM_IsArrayClass(JNIEnv *env, jclass cls); 450 451 JNIEXPORT jboolean JNICALL 452 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls); 453 454 JNIEXPORT jint JNICALL 455 JVM_GetClassModifiers(JNIEnv *env, jclass cls); 456 457 JNIEXPORT jobjectArray JNICALL 458 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass); 459 460 JNIEXPORT jclass JNICALL 461 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass); 462 463 JNIEXPORT jstring JNICALL 464 JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass); 465 466 /* Generics support (JDK 1.5) */ 467 JNIEXPORT jstring JNICALL 468 JVM_GetClassSignature(JNIEnv *env, jclass cls); 469 470 /* Annotations support (JDK 1.5) */ 471 JNIEXPORT jbyteArray JNICALL 472 JVM_GetClassAnnotations(JNIEnv *env, jclass cls); 473 474 /* Type use annotations support (JDK 1.8) */ 475 476 JNIEXPORT jbyteArray JNICALL 477 JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls); 478 479 JNIEXPORT jbyteArray JNICALL 480 JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field); 481 482 JNIEXPORT jbyteArray JNICALL 483 JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method); 484 485 /* 486 * New (JDK 1.4) reflection implementation 487 */ 488 489 JNIEXPORT jobjectArray JNICALL 490 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly); 491 492 JNIEXPORT jobjectArray JNICALL 493 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly); 494 495 JNIEXPORT jobjectArray JNICALL 496 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly); 497 498 /* Differs from JVM_GetClassModifiers in treatment of inner classes. 499 This returns the access flags for the class as specified in the 500 class file rather than searching the InnerClasses attribute (if 501 present) to find the source-level access flags. Only the values of 502 the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be 503 valid. */ 504 JNIEXPORT jint JNICALL 505 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls); 506 507 /* The following two reflection routines are still needed due to startup time issues */ 508 /* 509 * java.lang.reflect.Method 510 */ 511 JNIEXPORT jobject JNICALL 512 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0); 513 514 /* 515 * java.lang.reflect.Constructor 516 */ 517 JNIEXPORT jobject JNICALL 518 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0); 519 520 /* 521 * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5) 522 */ 523 524 JNIEXPORT jobject JNICALL 525 JVM_GetClassConstantPool(JNIEnv *env, jclass cls); 526 527 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize 528 (JNIEnv *env, jobject unused, jobject jcpool); 529 530 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt 531 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 532 533 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded 534 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 535 536 JNIEXPORT jint JNICALL JVM_ConstantPoolGetClassRefIndexAt 537 (JNIEnv *env, jobject obj, jobject unused, jint index); 538 539 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt 540 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 541 542 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded 543 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 544 545 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt 546 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 547 548 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded 549 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 550 551 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt 552 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 553 554 JNIEXPORT jint JNICALL JVM_ConstantPoolGetNameAndTypeRefIndexAt 555 (JNIEnv *env, jobject obj, jobject unused, jint index); 556 557 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetNameAndTypeRefInfoAt 558 (JNIEnv *env, jobject obj, jobject unused, jint index); 559 560 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt 561 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 562 563 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt 564 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 565 566 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt 567 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 568 569 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt 570 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 571 572 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt 573 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 574 575 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At 576 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 577 578 JNIEXPORT jbyte JNICALL JVM_ConstantPoolGetTagAt 579 (JNIEnv *env, jobject unused, jobject jcpool, jint index); 580 581 /* 582 * Parameter reflection 583 */ 584 585 JNIEXPORT jobjectArray JNICALL 586 JVM_GetMethodParameters(JNIEnv *env, jobject method); 587 588 /* 589 * java.security.* 590 */ 591 592 JNIEXPORT jobject JNICALL 593 JVM_DoPrivileged(JNIEnv *env, jclass cls, 594 jobject action, jobject context, jboolean wrapException); 595 596 JNIEXPORT jobject JNICALL 597 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls); 598 599 JNIEXPORT jobject JNICALL 600 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls); 601 602 /* 603 * Signal support, used to implement the shutdown sequence. Every VM must 604 * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts 605 * (^C) and the latter for external termination (kill, system shutdown, etc.). 606 * Other platform-dependent signal values may also be supported. 607 */ 608 609 JNIEXPORT void * JNICALL 610 JVM_RegisterSignal(jint sig, void *handler); 611 612 JNIEXPORT jboolean JNICALL 613 JVM_RaiseSignal(jint sig); 614 615 JNIEXPORT jint JNICALL 616 JVM_FindSignal(const char *name); 617 618 /* 619 * Retrieve the assertion directives for the specified class. 620 */ 621 JNIEXPORT jboolean JNICALL 622 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls); 623 624 /* 625 * Retrieve the assertion directives from the VM. 626 */ 627 JNIEXPORT jobject JNICALL 628 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused); 629 630 /* 631 * java.util.concurrent.atomic.AtomicLong 632 */ 633 JNIEXPORT jboolean JNICALL 634 JVM_SupportsCX8(void); 635 636 /* 637 * com.sun.dtrace.jsdt support 638 */ 639 640 #define JVM_TRACING_DTRACE_VERSION 1 641 642 /* 643 * Structure to pass one probe description to JVM 644 */ 645 typedef struct { 646 jmethodID method; 647 jstring function; 648 jstring name; 649 void* reserved[4]; // for future use 650 } JVM_DTraceProbe; 651 652 /** 653 * Encapsulates the stability ratings for a DTrace provider field 654 */ 655 typedef struct { 656 jint nameStability; 657 jint dataStability; 658 jint dependencyClass; 659 } JVM_DTraceInterfaceAttributes; 660 661 /* 662 * Structure to pass one provider description to JVM 663 */ 664 typedef struct { 665 jstring name; 666 JVM_DTraceProbe* probes; 667 jint probe_count; 668 JVM_DTraceInterfaceAttributes providerAttributes; 669 JVM_DTraceInterfaceAttributes moduleAttributes; 670 JVM_DTraceInterfaceAttributes functionAttributes; 671 JVM_DTraceInterfaceAttributes nameAttributes; 672 JVM_DTraceInterfaceAttributes argsAttributes; 673 void* reserved[4]; // for future use 674 } JVM_DTraceProvider; 675 676 /* 677 * Get the version number the JVM was built with 678 */ 679 JNIEXPORT jint JNICALL 680 JVM_DTraceGetVersion(JNIEnv* env); 681 682 /* 683 * Register new probe with given signature, return global handle 684 * 685 * The version passed in is the version that the library code was 686 * built with. 687 */ 688 JNIEXPORT jlong JNICALL 689 JVM_DTraceActivate(JNIEnv* env, jint version, jstring module_name, 690 jint providers_count, JVM_DTraceProvider* providers); 691 692 /* 693 * Check JSDT probe 694 */ 695 JNIEXPORT jboolean JNICALL 696 JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method); 697 698 /* 699 * Destroy custom DOF 700 */ 701 JNIEXPORT void JNICALL 702 JVM_DTraceDispose(JNIEnv* env, jlong activation_handle); 703 704 /* 705 * Check to see if DTrace is supported by OS 706 */ 707 JNIEXPORT jboolean JNICALL 708 JVM_DTraceIsSupported(JNIEnv* env); 709 710 /************************************************************************* 711 PART 2: Support for the Verifier and Class File Format Checker 712 ************************************************************************/ 713 /* 714 * Return the class name in UTF format. The result is valid 715 * until JVM_ReleaseUTf is called. 716 * 717 * The caller must treat the string as a constant and not modify it 718 * in any way. 719 */ 720 JNIEXPORT const char * JNICALL 721 JVM_GetClassNameUTF(JNIEnv *env, jclass cb); 722 723 /* 724 * Returns the constant pool types in the buffer provided by "types." 725 */ 726 JNIEXPORT void JNICALL 727 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types); 728 729 /* 730 * Returns the number of Constant Pool entries. 731 */ 732 JNIEXPORT jint JNICALL 733 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb); 734 735 /* 736 * Returns the number of *declared* fields or methods. 737 */ 738 JNIEXPORT jint JNICALL 739 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb); 740 741 JNIEXPORT jint JNICALL 742 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb); 743 744 /* 745 * Returns the CP indexes of exceptions raised by a given method. 746 * Places the result in the given buffer. 747 * 748 * The method is identified by method_index. 749 */ 750 JNIEXPORT void JNICALL 751 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index, 752 unsigned short *exceptions); 753 /* 754 * Returns the number of exceptions raised by a given method. 755 * The method is identified by method_index. 756 */ 757 JNIEXPORT jint JNICALL 758 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index); 759 760 /* 761 * Returns the byte code sequence of a given method. 762 * Places the result in the given buffer. 763 * 764 * The method is identified by method_index. 765 */ 766 JNIEXPORT void JNICALL 767 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index, 768 unsigned char *code); 769 770 /* 771 * Returns the length of the byte code sequence of a given method. 772 * The method is identified by method_index. 773 */ 774 JNIEXPORT jint JNICALL 775 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index); 776 777 /* 778 * A structure used to a capture exception table entry in a Java method. 779 */ 780 typedef struct { 781 jint start_pc; 782 jint end_pc; 783 jint handler_pc; 784 jint catchType; 785 } JVM_ExceptionTableEntryType; 786 787 /* 788 * Returns the exception table entry at entry_index of a given method. 789 * Places the result in the given buffer. 790 * 791 * The method is identified by method_index. 792 */ 793 JNIEXPORT void JNICALL 794 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index, 795 jint entry_index, 796 JVM_ExceptionTableEntryType *entry); 797 798 /* 799 * Returns the length of the exception table of a given method. 800 * The method is identified by method_index. 801 */ 802 JNIEXPORT jint JNICALL 803 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index); 804 805 /* 806 * Returns the modifiers of a given field. 807 * The field is identified by field_index. 808 */ 809 JNIEXPORT jint JNICALL 810 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index); 811 812 /* 813 * Returns the modifiers of a given method. 814 * The method is identified by method_index. 815 */ 816 JNIEXPORT jint JNICALL 817 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index); 818 819 /* 820 * Returns the number of local variables of a given method. 821 * The method is identified by method_index. 822 */ 823 JNIEXPORT jint JNICALL 824 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index); 825 826 /* 827 * Returns the number of arguments (including this pointer) of a given method. 828 * The method is identified by method_index. 829 */ 830 JNIEXPORT jint JNICALL 831 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index); 832 833 /* 834 * Returns the maximum amount of stack (in words) used by a given method. 835 * The method is identified by method_index. 836 */ 837 JNIEXPORT jint JNICALL 838 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index); 839 840 /* 841 * Is a given method a constructor. 842 * The method is identified by method_index. 843 */ 844 JNIEXPORT jboolean JNICALL 845 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index); 846 847 /* 848 * Is the given method generated by the VM. 849 * The method is identified by method_index. 850 */ 851 JNIEXPORT jboolean JNICALL 852 JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, int index); 853 854 /* 855 * Returns the name of a given method in UTF format. 856 * The result remains valid until JVM_ReleaseUTF is called. 857 * 858 * The caller must treat the string as a constant and not modify it 859 * in any way. 860 */ 861 JNIEXPORT const char * JNICALL 862 JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index); 863 864 /* 865 * Returns the signature of a given method in UTF format. 866 * The result remains valid until JVM_ReleaseUTF is called. 867 * 868 * The caller must treat the string as a constant and not modify it 869 * in any way. 870 */ 871 JNIEXPORT const char * JNICALL 872 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index); 873 874 /* 875 * Returns the name of the field referred to at a given constant pool 876 * index. 877 * 878 * The result is in UTF format and remains valid until JVM_ReleaseUTF 879 * is called. 880 * 881 * The caller must treat the string as a constant and not modify it 882 * in any way. 883 */ 884 JNIEXPORT const char * JNICALL 885 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index); 886 887 /* 888 * Returns the name of the method referred to at a given constant pool 889 * index. 890 * 891 * The result is in UTF format and remains valid until JVM_ReleaseUTF 892 * is called. 893 * 894 * The caller must treat the string as a constant and not modify it 895 * in any way. 896 */ 897 JNIEXPORT const char * JNICALL 898 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index); 899 900 /* 901 * Returns the signature of the method referred to at a given constant pool 902 * index. 903 * 904 * The result is in UTF format and remains valid until JVM_ReleaseUTF 905 * is called. 906 * 907 * The caller must treat the string as a constant and not modify it 908 * in any way. 909 */ 910 JNIEXPORT const char * JNICALL 911 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index); 912 913 /* 914 * Returns the signature of the field referred to at a given constant pool 915 * index. 916 * 917 * The result is in UTF format and remains valid until JVM_ReleaseUTF 918 * is called. 919 * 920 * The caller must treat the string as a constant and not modify it 921 * in any way. 922 */ 923 JNIEXPORT const char * JNICALL 924 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index); 925 926 /* 927 * Returns the class name referred to at a given constant pool index. 928 * 929 * The result is in UTF format and remains valid until JVM_ReleaseUTF 930 * is called. 931 * 932 * The caller must treat the string as a constant and not modify it 933 * in any way. 934 */ 935 JNIEXPORT const char * JNICALL 936 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index); 937 938 /* 939 * Returns the class name referred to at a given constant pool index. 940 * 941 * The constant pool entry must refer to a CONSTANT_Fieldref. 942 * 943 * The result is in UTF format and remains valid until JVM_ReleaseUTF 944 * is called. 945 * 946 * The caller must treat the string as a constant and not modify it 947 * in any way. 948 */ 949 JNIEXPORT const char * JNICALL 950 JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index); 951 952 /* 953 * Returns the class name referred to at a given constant pool index. 954 * 955 * The constant pool entry must refer to CONSTANT_Methodref or 956 * CONSTANT_InterfaceMethodref. 957 * 958 * The result is in UTF format and remains valid until JVM_ReleaseUTF 959 * is called. 960 * 961 * The caller must treat the string as a constant and not modify it 962 * in any way. 963 */ 964 JNIEXPORT const char * JNICALL 965 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index); 966 967 /* 968 * Returns the modifiers of a field in calledClass. The field is 969 * referred to in class cb at constant pool entry index. 970 * 971 * The caller must treat the string as a constant and not modify it 972 * in any way. 973 * 974 * Returns -1 if the field does not exist in calledClass. 975 */ 976 JNIEXPORT jint JNICALL 977 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 978 979 /* 980 * Returns the modifiers of a method in calledClass. The method is 981 * referred to in class cb at constant pool entry index. 982 * 983 * Returns -1 if the method does not exist in calledClass. 984 */ 985 JNIEXPORT jint JNICALL 986 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass); 987 988 /* 989 * Releases the UTF string obtained from the VM. 990 */ 991 JNIEXPORT void JNICALL 992 JVM_ReleaseUTF(const char *utf); 993 994 /* 995 * Compare if two classes are in the same package. 996 */ 997 JNIEXPORT jboolean JNICALL 998 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2); 999 1000 /* Get classfile constants */ 1001 #include "classfile_constants.h" 1002 1003 /* 1004 * A function defined by the byte-code verifier and called by the VM. 1005 * This is not a function implemented in the VM. 1006 * 1007 * Returns JNI_FALSE if verification fails. A detailed error message 1008 * will be places in msg_buf, whose length is specified by buf_len. 1009 */ 1010 typedef jboolean (*verifier_fn_t)(JNIEnv *env, 1011 jclass cb, 1012 char * msg_buf, 1013 jint buf_len); 1014 1015 1016 /* 1017 * Support for a VM-independent class format checker. 1018 */ 1019 typedef struct { 1020 unsigned long code; /* byte code */ 1021 unsigned long excs; /* exceptions */ 1022 unsigned long etab; /* catch table */ 1023 unsigned long lnum; /* line number */ 1024 unsigned long lvar; /* local vars */ 1025 } method_size_info; 1026 1027 typedef struct { 1028 unsigned int constants; /* constant pool */ 1029 unsigned int fields; 1030 unsigned int methods; 1031 unsigned int interfaces; 1032 unsigned int fields2; /* number of static 2-word fields */ 1033 unsigned int innerclasses; /* # of records in InnerClasses attr */ 1034 1035 method_size_info clinit; /* memory used in clinit */ 1036 method_size_info main; /* used everywhere else */ 1037 } class_size_info; 1038 1039 /* 1040 * Functions defined in libjava.so to perform string conversions. 1041 * 1042 */ 1043 1044 typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str); 1045 1046 typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b); 1047 1048 /* This is the function defined in libjava.so that performs class 1049 * format checks. This functions fills in size information about 1050 * the class file and returns: 1051 * 1052 * 0: good 1053 * -1: out of memory 1054 * -2: bad format 1055 * -3: unsupported version 1056 * -4: bad class name 1057 */ 1058 1059 typedef jint (*check_format_fn_t)(char *class_name, 1060 unsigned char *data, 1061 unsigned int data_size, 1062 class_size_info *class_size, 1063 char *message_buffer, 1064 jint buffer_length, 1065 jboolean measure_only, 1066 jboolean check_relaxed); 1067 1068 #define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \ 1069 JVM_ACC_FINAL | \ 1070 JVM_ACC_SUPER | \ 1071 JVM_ACC_INTERFACE | \ 1072 JVM_ACC_ABSTRACT | \ 1073 JVM_ACC_ANNOTATION | \ 1074 JVM_ACC_ENUM | \ 1075 JVM_ACC_SYNTHETIC) 1076 1077 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \ 1078 JVM_ACC_PRIVATE | \ 1079 JVM_ACC_PROTECTED | \ 1080 JVM_ACC_STATIC | \ 1081 JVM_ACC_FINAL | \ 1082 JVM_ACC_VOLATILE | \ 1083 JVM_ACC_TRANSIENT | \ 1084 JVM_ACC_ENUM | \ 1085 JVM_ACC_SYNTHETIC) 1086 1087 #define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \ 1088 JVM_ACC_PRIVATE | \ 1089 JVM_ACC_PROTECTED | \ 1090 JVM_ACC_STATIC | \ 1091 JVM_ACC_FINAL | \ 1092 JVM_ACC_SYNCHRONIZED | \ 1093 JVM_ACC_BRIDGE | \ 1094 JVM_ACC_VARARGS | \ 1095 JVM_ACC_NATIVE | \ 1096 JVM_ACC_ABSTRACT | \ 1097 JVM_ACC_STRICT | \ 1098 JVM_ACC_SYNTHETIC) 1099 1100 /* 1101 * This is the function defined in libjava.so to perform path 1102 * canonicalization. VM call this function before opening jar files 1103 * to load system classes. 1104 * 1105 */ 1106 1107 typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len); 1108 1109 /************************************************************************* 1110 PART 3: I/O and Network Support 1111 ************************************************************************/ 1112 1113 /* 1114 * Convert a pathname into native format. This function does syntactic 1115 * cleanup, such as removing redundant separator characters. It modifies 1116 * the given pathname string in place. 1117 */ 1118 JNIEXPORT char * JNICALL 1119 JVM_NativePath(char *); 1120 1121 /* 1122 * The standard printing functions supported by the Java VM. (Should they 1123 * be renamed to JVM_* in the future? 1124 */ 1125 1126 /* 1127 * BE CAREFUL! The following functions do not implement the 1128 * full feature set of standard C printf formats. 1129 */ 1130 int 1131 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args); 1132 1133 int 1134 jio_snprintf(char *str, size_t count, const char *fmt, ...); 1135 1136 int 1137 jio_fprintf(FILE *, const char *fmt, ...); 1138 1139 int 1140 jio_vfprintf(FILE *, const char *fmt, va_list args); 1141 1142 1143 JNIEXPORT void * JNICALL 1144 JVM_RawMonitorCreate(void); 1145 1146 JNIEXPORT void JNICALL 1147 JVM_RawMonitorDestroy(void *mon); 1148 1149 JNIEXPORT jint JNICALL 1150 JVM_RawMonitorEnter(void *mon); 1151 1152 JNIEXPORT void JNICALL 1153 JVM_RawMonitorExit(void *mon); 1154 1155 /* 1156 * java.lang.management support 1157 */ 1158 JNIEXPORT void* JNICALL 1159 JVM_GetManagement(jint version); 1160 1161 /* 1162 * com.sun.tools.attach.VirtualMachine support 1163 * 1164 * Initialize the agent properties with the properties maintained in the VM. 1165 */ 1166 JNIEXPORT jobject JNICALL 1167 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props); 1168 1169 JNIEXPORT jstring JNICALL 1170 JVM_GetTemporaryDirectory(JNIEnv *env); 1171 1172 /* Generics reflection support. 1173 * 1174 * Returns information about the given class's EnclosingMethod 1175 * attribute, if present, or null if the class had no enclosing 1176 * method. 1177 * 1178 * If non-null, the returned array contains three elements. Element 0 1179 * is the java.lang.Class of which the enclosing method is a member, 1180 * and elements 1 and 2 are the java.lang.Strings for the enclosing 1181 * method's name and descriptor, respectively. 1182 */ 1183 JNIEXPORT jobjectArray JNICALL 1184 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass); 1185 1186 /* ========================================================================= 1187 * The following defines a private JVM interface that the JDK can query 1188 * for the JVM version and capabilities. sun.misc.Version defines 1189 * the methods for getting the VM version and its capabilities. 1190 * 1191 * When a new bit is added, the following should be updated to provide 1192 * access to the new capability: 1193 * HS: JVM_GetVersionInfo and Abstract_VM_Version class 1194 * SDK: Version class 1195 * 1196 * Similary, a private JDK interface JDK_GetVersionInfo0 is defined for 1197 * JVM to query for the JDK version and capabilities. 1198 * 1199 * When a new bit is added, the following should be updated to provide 1200 * access to the new capability: 1201 * HS: JDK_Version class 1202 * SDK: JDK_GetVersionInfo0 1203 * 1204 * ========================================================================== 1205 */ 1206 typedef struct { 1207 unsigned int jvm_version; /* Encoded $VNUM as specified by JEP-223 */ 1208 unsigned int patch_version : 8; /* JEP-223 patch version */ 1209 unsigned int reserved3 : 8; 1210 unsigned int reserved1 : 16; 1211 unsigned int reserved2; 1212 1213 /* The following bits represents JVM supports that JDK has dependency on. 1214 * JDK can use these bits to determine which JVM version 1215 * and support it has to maintain runtime compatibility. 1216 * 1217 * When a new bit is added in a minor or update release, make sure 1218 * the new bit is also added in the main/baseline. 1219 */ 1220 unsigned int is_attach_supported : 1; 1221 unsigned int : 31; 1222 unsigned int : 32; 1223 unsigned int : 32; 1224 } jvm_version_info; 1225 1226 #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1227 #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1228 #define JVM_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) 1229 #define JVM_VERSION_BUILD(version) ((version & 0x000000FF)) 1230 1231 JNIEXPORT void JNICALL 1232 JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size); 1233 1234 typedef struct { 1235 unsigned int jdk_version; /* Encoded $VNUM as specified by JEP-223 */ 1236 unsigned int patch_version : 8; /* JEP-223 patch version */ 1237 unsigned int reserved3 : 8; 1238 unsigned int reserved1 : 16; 1239 unsigned int reserved2; 1240 1241 /* The following bits represents new JDK supports that VM has dependency on. 1242 * VM implementation can use these bits to determine which JDK version 1243 * and support it has to maintain runtime compatibility. 1244 * 1245 * When a new bit is added in a minor or update release, make sure 1246 * the new bit is also added in the main/baseline. 1247 */ 1248 unsigned int thread_park_blocker : 1; 1249 unsigned int post_vm_init_hook_enabled : 1; 1250 unsigned int pending_list_uses_discovered_field : 1; 1251 unsigned int : 29; 1252 unsigned int : 32; 1253 unsigned int : 32; 1254 } jdk_version_info; 1255 1256 #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24) 1257 #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16) 1258 #define JDK_VERSION_SECURITY(version) ((version & 0x0000FF00) >> 8) 1259 #define JDK_VERSION_BUILD(version) ((version & 0x000000FF)) 1260 1261 /* 1262 * This is the function JDK_GetVersionInfo0 defined in libjava.so 1263 * that is dynamically looked up by JVM. 1264 */ 1265 typedef void (*jdk_version_info_fn_t)(jdk_version_info* info, size_t info_size); 1266 1267 /* 1268 * This structure is used by the launcher to get the default thread 1269 * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a 1270 * version of 1.1. As it is not supported otherwise, it has been removed 1271 * from jni.h 1272 */ 1273 typedef struct JDK1_1InitArgs { 1274 jint version; 1275 1276 char **properties; 1277 jint checkSource; 1278 jint nativeStackSize; 1279 jint javaStackSize; 1280 jint minHeapSize; 1281 jint maxHeapSize; 1282 jint verifyMode; 1283 char *classpath; 1284 1285 jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args); 1286 void (JNICALL *exit)(jint code); 1287 void (JNICALL *abort)(void); 1288 1289 jint enableClassGC; 1290 jint enableVerboseGC; 1291 jint disableAsyncGC; 1292 jint verbose; 1293 jboolean debugging; 1294 jint debugPort; 1295 } JDK1_1InitArgs; 1296 1297 1298 #ifdef __cplusplus 1299 } /* extern "C" */ 1300 1301 #endif /* __cplusplus */ 1302 1303 #endif /* !_JAVASOFT_JVM_H_ */