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