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