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