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