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