1 /*
   2  * Copyright (c) 1997, 2022, 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 #include "jvm_constants.h"
  34 #include "jvm_io.h"
  35 
  36 #ifdef __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 /*
  41  * This file contains additional functions exported from the VM.
  42  * These functions are complementary to the standard JNI support.
  43  * There are three parts to this file:
  44  *
  45  * First, this file contains the VM-related functions needed by native
  46  * libraries in the standard Java API. For example, the java.lang.Object
  47  * class needs VM-level functions that wait for and notify monitors.
  48  *
  49  * Second, (included from jvm_constants.h) constant definitions
  50  * needed by the byte code verifier and class file format checker.
  51  * These definitions allow the verifier and format checker to be written
  52  * in a VM-independent way.
  53  *
  54  * Third, this file contains various I/O and network operations needed
  55  * by the standard Java I/O and network APIs. A part of these APIs,
  56  * namely the jio_xxxprintf functions, are included from jvm_io.h.
  57  */
  58 
  59 
  60 /*************************************************************************
  61  PART 1: Functions for Native Libraries
  62  ************************************************************************/
  63 /*
  64  * java.lang.Object
  65  */
  66 JNIEXPORT jint JNICALL
  67 JVM_IHashCode(JNIEnv *env, jobject obj);
  68 
  69 JNIEXPORT void JNICALL
  70 JVM_MonitorWait(JNIEnv *env, jobject obj, jlong ms);
  71 
  72 JNIEXPORT void JNICALL
  73 JVM_MonitorNotify(JNIEnv *env, jobject obj);
  74 
  75 JNIEXPORT void JNICALL
  76 JVM_MonitorNotifyAll(JNIEnv *env, jobject obj);
  77 
  78 JNIEXPORT jobject JNICALL
  79 JVM_Clone(JNIEnv *env, jobject obj);
  80 
  81 /*
  82  * java.lang.String
  83  */
  84 JNIEXPORT jstring JNICALL
  85 JVM_InternString(JNIEnv *env, jstring str);
  86 
  87 /*
  88  * java.lang.System
  89  */
  90 JNIEXPORT jlong JNICALL
  91 JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored);
  92 
  93 JNIEXPORT jlong JNICALL
  94 JVM_NanoTime(JNIEnv *env, jclass ignored);
  95 
  96 JNIEXPORT jlong JNICALL
  97 JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs);
  98 
  99 JNIEXPORT void JNICALL
 100 JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
 101               jobject dst, jint dst_pos, jint length);
 102 
 103 /*
 104  * Return an array of all properties as alternating name and value pairs.
 105  */
 106 JNIEXPORT jobjectArray JNICALL
 107 JVM_GetProperties(JNIEnv *env);
 108 
 109 /*
 110  * java.lang.Runtime
 111  */
 112 JNIEXPORT void JNICALL
 113 JVM_BeforeHalt();
 114 
 115 JNIEXPORT void JNICALL
 116 JVM_Halt(jint code);
 117 
 118 JNIEXPORT void JNICALL
 119 JVM_GC(void);
 120 
 121 /* Returns the number of real-time milliseconds that have elapsed since the
 122  * least-recently-inspected heap object was last inspected by the garbage
 123  * collector.
 124  *
 125  * For simple stop-the-world collectors this value is just the time
 126  * since the most recent collection.  For generational collectors it is the
 127  * time since the oldest generation was most recently collected.  Other
 128  * collectors are free to return a pessimistic estimate of the elapsed time, or
 129  * simply the time since the last full collection was performed.
 130  *
 131  * Note that in the presence of reference objects, a given object that is no
 132  * longer strongly reachable may have to be inspected multiple times before it
 133  * can be reclaimed.
 134  */
 135 JNIEXPORT jlong JNICALL
 136 JVM_MaxObjectInspectionAge(void);
 137 
 138 JNIEXPORT jlong JNICALL
 139 JVM_TotalMemory(void);
 140 
 141 JNIEXPORT jlong JNICALL
 142 JVM_FreeMemory(void);
 143 
 144 JNIEXPORT jlong JNICALL
 145 JVM_MaxMemory(void);
 146 
 147 JNIEXPORT jint JNICALL
 148 JVM_ActiveProcessorCount(void);
 149 
 150 JNIEXPORT jboolean JNICALL
 151 JVM_IsUseContainerSupport(void);
 152 
 153 JNIEXPORT void * JNICALL
 154 JVM_LoadZipLibrary();
 155 
 156 JNIEXPORT void * JNICALL
 157 JVM_LoadLibrary(const char *name, jboolean throwException);
 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 JNIEXPORT jobjectArray JNICALL
 169 JVM_GetVmArguments(JNIEnv *env);
 170 
 171 JNIEXPORT jboolean JNICALL
 172 JVM_IsPreviewEnabled(void);
 173 
 174 JNIEXPORT jboolean JNICALL
 175 JVM_IsContinuationsSupported(void);
 176 
 177 JNIEXPORT void JNICALL
 178 JVM_InitializeFromArchive(JNIEnv* env, jclass cls);
 179 
 180 JNIEXPORT void JNICALL
 181 JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env, jclass caller,
 182                                          jstring interfaceMethodName,
 183                                          jobject factoryType,
 184                                          jobject interfaceMethodType,
 185                                          jobject implementationMember,
 186                                          jobject dynamicMethodType,
 187                                          jclass lambdaProxyClass);
 188 
 189 JNIEXPORT jclass JNICALL
 190 JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env, jclass caller,
 191                                       jstring interfaceMethodName,
 192                                       jobject factoryType,
 193                                       jobject interfaceMethodType,
 194                                       jobject implementationMember,
 195                                       jobject dynamicMethodType);
 196 
 197 JNIEXPORT jboolean JNICALL
 198 JVM_IsCDSDumpingEnabled(JNIEnv* env);
 199 
 200 JNIEXPORT jboolean JNICALL
 201 JVM_IsSharingEnabled(JNIEnv* env);
 202 
 203 JNIEXPORT jboolean JNICALL
 204 JVM_IsDumpingClassList(JNIEnv* env);
 205 
 206 JNIEXPORT jlong JNICALL
 207 JVM_GetRandomSeedForDumping();
 208 
 209 JNIEXPORT void JNICALL
 210 JVM_LogLambdaFormInvoker(JNIEnv* env, jstring line);
 211 
 212 JNIEXPORT void JNICALL
 213 JVM_DumpClassListToFile(JNIEnv* env, jstring fileName);
 214 
 215 JNIEXPORT void JNICALL
 216 JVM_DumpDynamicArchive(JNIEnv* env, jstring archiveName);
 217 
 218 /*
 219  * java.lang.Throwable
 220  */
 221 JNIEXPORT void JNICALL
 222 JVM_FillInStackTrace(JNIEnv *env, jobject throwable);
 223 
 224 /*
 225  * java.lang.StackTraceElement
 226  */
 227 JNIEXPORT void JNICALL
 228 JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject backtrace, jint depth);
 229 
 230 JNIEXPORT void JNICALL
 231 JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo);
 232 
 233 /*
 234  * java.lang.NullPointerException
 235  */
 236 
 237 JNIEXPORT jstring JNICALL
 238 JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable);
 239 
 240 /*
 241  * java.lang.StackWalker
 242  */
 243 enum {
 244   JVM_STACKWALK_FILL_CLASS_REFS_ONLY       = 0x2,
 245   JVM_STACKWALK_GET_CALLER_CLASS           = 0x04,
 246   JVM_STACKWALK_SHOW_HIDDEN_FRAMES         = 0x20,
 247   JVM_STACKWALK_FILL_LIVE_STACK_FRAMES     = 0x100
 248 };
 249 
 250 JNIEXPORT jobject JNICALL
 251 JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 252                   jint skip_frames, jobject contScope, jobject cont,
 253                   jint frame_count, jint start_index, jobjectArray frames);
 254 
 255 JNIEXPORT jint JNICALL
 256 JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 257                   jint frame_count, jint start_index,
 258                   jobjectArray frames);
 259 
 260 JNIEXPORT void JNICALL
 261 JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont);
 262 
 263 /*
 264  * java.lang.Thread
 265  */
 266 JNIEXPORT void JNICALL
 267 JVM_StartThread(JNIEnv *env, jobject thread);
 268 
 269 JNIEXPORT jboolean JNICALL
 270 JVM_IsThreadAlive(JNIEnv *env, jobject thread);
 271 
 272 JNIEXPORT void JNICALL
 273 JVM_SetThreadPriority(JNIEnv *env, jobject thread, jint prio);
 274 
 275 JNIEXPORT void JNICALL
 276 JVM_Yield(JNIEnv *env, jclass threadClass);
 277 
 278 JNIEXPORT void JNICALL
 279 JVM_Sleep(JNIEnv *env, jclass threadClass, jlong millis);
 280 
 281 JNIEXPORT jobject JNICALL
 282 JVM_CurrentCarrierThread(JNIEnv *env, jclass threadClass);
 283 
 284 JNIEXPORT jobject JNICALL
 285 JVM_CurrentThread(JNIEnv *env, jclass threadClass);
 286 
 287 JNIEXPORT void JNICALL
 288 JVM_SetCurrentThread(JNIEnv *env, jobject thisThread, jobject theThread);
 289 
 290 JNIEXPORT void JNICALL
 291 JVM_Interrupt(JNIEnv *env, jobject thread);
 292 
 293 JNIEXPORT jboolean JNICALL
 294 JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj);
 295 
 296 JNIEXPORT jobject JNICALL
 297 JVM_GetStackTrace(JNIEnv *env, jobject thread);
 298 
 299 JNIEXPORT void JNICALL
 300 JVM_DumpAllStacks(JNIEnv *env, jclass unused);
 301 
 302 JNIEXPORT jobjectArray JNICALL
 303 JVM_GetAllThreads(JNIEnv *env, jclass dummy);
 304 
 305 JNIEXPORT void JNICALL
 306 JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name);
 307 
 308 /* getStackTrace() and getAllStackTraces() method */
 309 JNIEXPORT jobjectArray JNICALL
 310 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads);
 311 
 312 JNIEXPORT jobject JNICALL
 313 JVM_ExtentLocalCache(JNIEnv *env, jclass threadClass);
 314 
 315 JNIEXPORT void JNICALL
 316 JVM_SetExtentLocalCache(JNIEnv *env, jclass threadClass, jobject theCache);
 317 
 318 JNIEXPORT jlong JNICALL
 319 JVM_GetNextThreadIdOffset(JNIEnv *env, jclass threadClass);
 320 
 321 /*
 322  * jdk.internal.vm.Continuation
 323  */
 324 JNIEXPORT void JNICALL
 325 JVM_RegisterContinuationMethods(JNIEnv *env, jclass cls);
 326 
 327 /*
 328  * java.lang.SecurityManager
 329  */
 330 JNIEXPORT jobjectArray JNICALL
 331 JVM_GetClassContext(JNIEnv *env);
 332 
 333 /*
 334  * java.lang.Package
 335  */
 336 JNIEXPORT jstring JNICALL
 337 JVM_GetSystemPackage(JNIEnv *env, jstring name);
 338 
 339 JNIEXPORT jobjectArray JNICALL
 340 JVM_GetSystemPackages(JNIEnv *env);
 341 
 342 /*
 343  * java.lang.ref.Reference
 344  */
 345 JNIEXPORT jobject JNICALL
 346 JVM_GetAndClearReferencePendingList(JNIEnv *env);
 347 
 348 JNIEXPORT jboolean JNICALL
 349 JVM_HasReferencePendingList(JNIEnv *env);
 350 
 351 JNIEXPORT void JNICALL
 352 JVM_WaitForReferencePendingList(JNIEnv *env);
 353 
 354 JNIEXPORT jboolean JNICALL
 355 JVM_ReferenceRefersTo(JNIEnv *env, jobject ref, jobject o);
 356 
 357 JNIEXPORT void JNICALL
 358 JVM_ReferenceClear(JNIEnv *env, jobject ref);
 359 
 360 /*
 361  * java.lang.ref.PhantomReference
 362  */
 363 JNIEXPORT jboolean JNICALL
 364 JVM_PhantomReferenceRefersTo(JNIEnv *env, jobject ref, jobject o);
 365 
 366 /*
 367  * java.io.ObjectInputStream
 368  */
 369 JNIEXPORT jobject JNICALL
 370 JVM_LatestUserDefinedLoader(JNIEnv *env);
 371 
 372 /*
 373  * java.lang.reflect.Array
 374  */
 375 JNIEXPORT jint JNICALL
 376 JVM_GetArrayLength(JNIEnv *env, jobject arr);
 377 
 378 JNIEXPORT jobject JNICALL
 379 JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index);
 380 
 381 JNIEXPORT jvalue JNICALL
 382 JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode);
 383 
 384 JNIEXPORT void JNICALL
 385 JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val);
 386 
 387 JNIEXPORT void JNICALL
 388 JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v,
 389                              unsigned char vCode);
 390 
 391 JNIEXPORT jobject JNICALL
 392 JVM_NewArray(JNIEnv *env, jclass eltClass, jint length);
 393 
 394 JNIEXPORT jobject JNICALL
 395 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim);
 396 
 397 
 398 /*
 399  * Returns the immediate caller class of the native method invoking
 400  * JVM_GetCallerClass.  The Method.invoke and other frames due to
 401  * reflection machinery are skipped.
 402  *
 403  * The caller is expected to be marked with
 404  * jdk.internal.reflect.CallerSensitive. The JVM will throw an
 405  * error if it is not marked properly.
 406  */
 407 JNIEXPORT jclass JNICALL
 408 JVM_GetCallerClass(JNIEnv *env);
 409 
 410 
 411 /*
 412  * Find primitive classes
 413  * utf: class name
 414  */
 415 JNIEXPORT jclass JNICALL
 416 JVM_FindPrimitiveClass(JNIEnv *env, const char *utf);
 417 
 418 
 419 /*
 420  * Find a class from a boot class loader. Returns NULL if class not found.
 421  */
 422 JNIEXPORT jclass JNICALL
 423 JVM_FindClassFromBootLoader(JNIEnv *env, const char *name);
 424 
 425 /*
 426  * Find a class from a given class loader.  Throws ClassNotFoundException.
 427  *  name:   name of class
 428  *  init:   whether initialization is done
 429  *  loader: class loader to look up the class. This may not be the same as the caller's
 430  *          class loader.
 431  *  caller: initiating class. The initiating class may be null when a security
 432  *          manager is not installed.
 433  */
 434 JNIEXPORT jclass JNICALL
 435 JVM_FindClassFromCaller(JNIEnv *env, const char *name, jboolean init,
 436                         jobject loader, jclass caller);
 437 
 438 /*
 439  * Find a class from a given class.
 440  */
 441 JNIEXPORT jclass JNICALL
 442 JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init,
 443                              jclass from);
 444 
 445 /* Find a loaded class cached by the VM */
 446 JNIEXPORT jclass JNICALL
 447 JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name);
 448 
 449 /* Define a class */
 450 JNIEXPORT jclass JNICALL
 451 JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
 452                 jsize len, jobject pd);
 453 
 454 /* Define a class with a source (added in JDK1.5) */
 455 JNIEXPORT jclass JNICALL
 456 JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
 457                           const jbyte *buf, jsize len, jobject pd,
 458                           const char *source);
 459 
 460 /*
 461  * Define a class with the specified lookup class.
 462  *  lookup:  Lookup class
 463  *  name:    the name of the class
 464  *  buf:     class bytes
 465  *  len:     length of class bytes
 466  *  pd:      protection domain
 467  *  init:    initialize the class
 468  *  flags:   properties of the class
 469  *  classData: private static pre-initialized field; may be null
 470  */
 471 JNIEXPORT jclass JNICALL
 472 JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, const jbyte *buf,
 473                       jsize len, jobject pd, jboolean init, int flags, jobject classData);
 474 
 475 /*
 476  * Module support functions
 477  */
 478 
 479 /*
 480  * Define a module with the specified packages and bind the module to the
 481  * given class loader.
 482  *  module:       module to define
 483  *  is_open:      specifies if module is open (currently ignored)
 484  *  version:      the module version
 485  *  location:     the module location
 486  *  packages:     array of packages in the module
 487  */
 488 JNIEXPORT void JNICALL
 489 JVM_DefineModule(JNIEnv *env, jobject module, jboolean is_open, jstring version,
 490                  jstring location, jobjectArray packages);
 491 
 492 /*
 493  * Set the boot loader's unnamed module.
 494  *  module: boot loader's unnamed module
 495  */
 496 JNIEXPORT void JNICALL
 497 JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module);
 498 
 499 /*
 500  * Do a qualified export of a package.
 501  *  from_module: module containing the package to export
 502  *  package:     name of the package to export
 503  *  to_module:   module to export the package to
 504  */
 505 JNIEXPORT void JNICALL
 506 JVM_AddModuleExports(JNIEnv *env, jobject from_module, jstring package, jobject to_module);
 507 
 508 /*
 509  * Do an export of a package to all unnamed modules.
 510  *  from_module: module containing the package to export
 511  *  package:     name of the package to export to all unnamed modules
 512  */
 513 JNIEXPORT void JNICALL
 514 JVM_AddModuleExportsToAllUnnamed(JNIEnv *env, jobject from_module, jstring package);
 515 
 516 /*
 517  * Do an unqualified export of a package.
 518  *  from_module: module containing the package to export
 519  *  package:     name of the package to export
 520  */
 521 JNIEXPORT void JNICALL
 522 JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, jstring package);
 523 
 524 /*
 525  * Add a module to the list of modules that a given module can read.
 526  *  from_module:   module requesting read access
 527  *  source_module: module that from_module wants to read
 528  */
 529 JNIEXPORT void JNICALL
 530 JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject source_module);
 531 
 532 /*
 533  * Define all modules that have been stored in the CDS archived heap.
 534  *  platform_loader: the built-in platform class loader
 535  *  system_loader:   the built-in system class loader
 536  */
 537 JNIEXPORT void JNICALL
 538 JVM_DefineArchivedModules(JNIEnv *env, jobject platform_loader, jobject system_loader);
 539 
 540 /*
 541  * Reflection support functions
 542  */
 543 
 544 JNIEXPORT jstring JNICALL
 545 JVM_InitClassName(JNIEnv *env, jclass cls);
 546 
 547 JNIEXPORT jobjectArray JNICALL
 548 JVM_GetClassInterfaces(JNIEnv *env, jclass cls);
 549 
 550 JNIEXPORT jboolean JNICALL
 551 JVM_IsInterface(JNIEnv *env, jclass cls);
 552 
 553 JNIEXPORT jobjectArray JNICALL
 554 JVM_GetClassSigners(JNIEnv *env, jclass cls);
 555 
 556 JNIEXPORT void JNICALL
 557 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers);
 558 
 559 JNIEXPORT jobject JNICALL
 560 JVM_GetProtectionDomain(JNIEnv *env, jclass cls);
 561 
 562 JNIEXPORT jboolean JNICALL
 563 JVM_IsArrayClass(JNIEnv *env, jclass cls);
 564 
 565 JNIEXPORT jboolean JNICALL
 566 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls);
 567 
 568 JNIEXPORT jboolean JNICALL
 569 JVM_IsHiddenClass(JNIEnv *env, jclass cls);
 570 
 571 JNIEXPORT jint JNICALL
 572 JVM_GetClassModifiers(JNIEnv *env, jclass cls);
 573 
 574 JNIEXPORT jobjectArray JNICALL
 575 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass);
 576 
 577 JNIEXPORT jclass JNICALL
 578 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass);
 579 
 580 JNIEXPORT jstring JNICALL
 581 JVM_GetSimpleBinaryName(JNIEnv *env, jclass ofClass);
 582 
 583 /* Generics support (JDK 1.5) */
 584 JNIEXPORT jstring JNICALL
 585 JVM_GetClassSignature(JNIEnv *env, jclass cls);
 586 
 587 /* Annotations support (JDK 1.5) */
 588 JNIEXPORT jbyteArray JNICALL
 589 JVM_GetClassAnnotations(JNIEnv *env, jclass cls);
 590 
 591 /* Type use annotations support (JDK 1.8) */
 592 
 593 JNIEXPORT jbyteArray JNICALL
 594 JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls);
 595 
 596 JNIEXPORT jbyteArray JNICALL
 597 JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field);
 598 
 599 JNIEXPORT jbyteArray JNICALL
 600 JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method);
 601 
 602 /*
 603  * New (JDK 1.4) reflection implementation
 604  */
 605 
 606 JNIEXPORT jobjectArray JNICALL
 607 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 608 
 609 JNIEXPORT jobjectArray JNICALL
 610 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 611 
 612 JNIEXPORT jobjectArray JNICALL
 613 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 614 
 615 
 616 /* Differs from JVM_GetClassModifiers in treatment of inner classes.
 617    This returns the access flags for the class as specified in the
 618    class file rather than searching the InnerClasses attribute (if
 619    present) to find the source-level access flags. Only the values of
 620    the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
 621    valid. */
 622 JNIEXPORT jint JNICALL
 623 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls);
 624 
 625 /* Nestmates - since JDK 11 */
 626 
 627 JNIEXPORT jboolean JNICALL
 628 JVM_AreNestMates(JNIEnv *env, jclass current, jclass member);
 629 
 630 JNIEXPORT jclass JNICALL
 631 JVM_GetNestHost(JNIEnv *env, jclass current);
 632 
 633 JNIEXPORT jobjectArray JNICALL
 634 JVM_GetNestMembers(JNIEnv *env, jclass current);
 635 
 636 /* Records - since JDK 16 */
 637 
 638 JNIEXPORT jboolean JNICALL
 639 JVM_IsRecord(JNIEnv *env, jclass cls);
 640 
 641 JNIEXPORT jobjectArray JNICALL
 642 JVM_GetRecordComponents(JNIEnv *env, jclass ofClass);
 643 
 644 /* Sealed classes - since JDK 17 */
 645 
 646 JNIEXPORT jobjectArray JNICALL
 647 JVM_GetPermittedSubclasses(JNIEnv *env, jclass current);
 648 
 649 /* The following two reflection routines are still needed due to startup time issues */
 650 /*
 651  * java.lang.reflect.Method
 652  */
 653 JNIEXPORT jobject JNICALL
 654 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0);
 655 
 656 /*
 657  * java.lang.reflect.Constructor
 658  */
 659 JNIEXPORT jobject JNICALL
 660 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0);
 661 
 662 /*
 663  * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5)
 664  */
 665 
 666 JNIEXPORT jobject JNICALL
 667 JVM_GetClassConstantPool(JNIEnv *env, jclass cls);
 668 
 669 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize
 670 (JNIEnv *env, jobject unused, jobject jcpool);
 671 
 672 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt
 673 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 674 
 675 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded
 676 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 677 
 678 JNIEXPORT jint JNICALL JVM_ConstantPoolGetClassRefIndexAt
 679 (JNIEnv *env, jobject obj, jobject unused, jint index);
 680 
 681 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt
 682 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 683 
 684 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded
 685 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 686 
 687 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt
 688 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 689 
 690 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded
 691 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 692 
 693 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt
 694 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 695 
 696 JNIEXPORT jint JNICALL JVM_ConstantPoolGetNameAndTypeRefIndexAt
 697 (JNIEnv *env, jobject obj, jobject unused, jint index);
 698 
 699 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetNameAndTypeRefInfoAt
 700 (JNIEnv *env, jobject obj, jobject unused, jint index);
 701 
 702 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt
 703 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 704 
 705 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt
 706 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 707 
 708 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt
 709 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 710 
 711 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt
 712 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 713 
 714 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt
 715 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 716 
 717 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At
 718 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 719 
 720 JNIEXPORT jbyte JNICALL JVM_ConstantPoolGetTagAt
 721 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 722 
 723 /*
 724  * Parameter reflection
 725  */
 726 
 727 JNIEXPORT jobjectArray JNICALL
 728 JVM_GetMethodParameters(JNIEnv *env, jobject method);
 729 
 730 /*
 731  * java.security.*
 732  */
 733 
 734 JNIEXPORT jobject JNICALL
 735 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls);
 736 
 737 /*
 738  * Ensure that code doing a stackwalk and using javaVFrame::locals() to
 739  * get the value will see a materialized value and not a scalar-replaced
 740  * null value.
 741  */
 742 #define JVM_EnsureMaterializedForStackWalk(env, value) \
 743     do {} while(0) // Nothing to do.  The fact that the value escaped
 744                    // through a native method is enough.
 745 
 746 JNIEXPORT jobject JNICALL
 747 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls);
 748 
 749 /*
 750  * Signal support, used to implement the shutdown sequence.  Every VM must
 751  * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts
 752  * (^C) and the latter for external termination (kill, system shutdown, etc.).
 753  * Other platform-dependent signal values may also be supported.
 754  */
 755 
 756 JNIEXPORT void * JNICALL
 757 JVM_RegisterSignal(jint sig, void *handler);
 758 
 759 JNIEXPORT jboolean JNICALL
 760 JVM_RaiseSignal(jint sig);
 761 
 762 JNIEXPORT jint JNICALL
 763 JVM_FindSignal(const char *name);
 764 
 765 /*
 766  * Retrieve the assertion directives for the specified class.
 767  */
 768 JNIEXPORT jboolean JNICALL
 769 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls);
 770 
 771 /*
 772  * Retrieve the assertion directives from the VM.
 773  */
 774 JNIEXPORT jobject JNICALL
 775 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused);
 776 
 777 /*
 778  * java.util.concurrent.atomic.AtomicLong
 779  */
 780 JNIEXPORT jboolean JNICALL
 781 JVM_SupportsCX8(void);
 782 
 783 /*
 784  * java.lang.ref.Finalizer
 785  */
 786 JNIEXPORT void JNICALL
 787 JVM_ReportFinalizationComplete(JNIEnv *env, jobject finalizee);
 788 
 789 JNIEXPORT jboolean JNICALL
 790 JVM_IsFinalizationEnabled(JNIEnv *env);
 791 
 792 /*************************************************************************
 793  PART 2: Support for the Verifier and Class File Format Checker
 794  ************************************************************************/
 795 /*
 796  * Return the class name in UTF format. The result is valid
 797  * until JVM_ReleaseUTf is called.
 798  *
 799  * The caller must treat the string as a constant and not modify it
 800  * in any way.
 801  */
 802 JNIEXPORT const char * JNICALL
 803 JVM_GetClassNameUTF(JNIEnv *env, jclass cb);
 804 
 805 /*
 806  * Returns the constant pool types in the buffer provided by "types."
 807  */
 808 JNIEXPORT void JNICALL
 809 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types);
 810 
 811 /*
 812  * Returns the number of Constant Pool entries.
 813  */
 814 JNIEXPORT jint JNICALL
 815 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb);
 816 
 817 /*
 818  * Returns the number of *declared* fields or methods.
 819  */
 820 JNIEXPORT jint JNICALL
 821 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb);
 822 
 823 JNIEXPORT jint JNICALL
 824 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb);
 825 
 826 /*
 827  * Returns the CP indexes of exceptions raised by a given method.
 828  * Places the result in the given buffer.
 829  *
 830  * The method is identified by method_index.
 831  */
 832 JNIEXPORT void JNICALL
 833 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index,
 834                                 unsigned short *exceptions);
 835 /*
 836  * Returns the number of exceptions raised by a given method.
 837  * The method is identified by method_index.
 838  */
 839 JNIEXPORT jint JNICALL
 840 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index);
 841 
 842 /*
 843  * Returns the byte code sequence of a given method.
 844  * Places the result in the given buffer.
 845  *
 846  * The method is identified by method_index.
 847  */
 848 JNIEXPORT void JNICALL
 849 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index,
 850                         unsigned char *code);
 851 
 852 /*
 853  * Returns the length of the byte code sequence of a given method.
 854  * The method is identified by method_index.
 855  */
 856 JNIEXPORT jint JNICALL
 857 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index);
 858 
 859 /*
 860  * A structure used to a capture exception table entry in a Java method.
 861  */
 862 typedef struct {
 863     jint start_pc;
 864     jint end_pc;
 865     jint handler_pc;
 866     jint catchType;
 867 } JVM_ExceptionTableEntryType;
 868 
 869 /*
 870  * Returns the exception table entry at entry_index of a given method.
 871  * Places the result in the given buffer.
 872  *
 873  * The method is identified by method_index.
 874  */
 875 JNIEXPORT void JNICALL
 876 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index,
 877                                    jint entry_index,
 878                                    JVM_ExceptionTableEntryType *entry);
 879 
 880 /*
 881  * Returns the length of the exception table of a given method.
 882  * The method is identified by method_index.
 883  */
 884 JNIEXPORT jint JNICALL
 885 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index);
 886 
 887 /*
 888  * Returns the modifiers of a given field.
 889  * The field is identified by field_index.
 890  */
 891 JNIEXPORT jint JNICALL
 892 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index);
 893 
 894 /*
 895  * Returns the modifiers of a given method.
 896  * The method is identified by method_index.
 897  */
 898 JNIEXPORT jint JNICALL
 899 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index);
 900 
 901 /*
 902  * Returns the number of local variables of a given method.
 903  * The method is identified by method_index.
 904  */
 905 JNIEXPORT jint JNICALL
 906 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index);
 907 
 908 /*
 909  * Returns the number of arguments (including this pointer) of a given method.
 910  * The method is identified by method_index.
 911  */
 912 JNIEXPORT jint JNICALL
 913 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index);
 914 
 915 /*
 916  * Returns the maximum amount of stack (in words) used by a given method.
 917  * The method is identified by method_index.
 918  */
 919 JNIEXPORT jint JNICALL
 920 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index);
 921 
 922 /*
 923  * Is a given method a constructor.
 924  * The method is identified by method_index.
 925  */
 926 JNIEXPORT jboolean JNICALL
 927 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index);
 928 
 929 /*
 930  * Is the given method generated by the VM.
 931  * The method is identified by method_index.
 932  */
 933 JNIEXPORT jboolean JNICALL
 934 JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cb, int index);
 935 
 936 /*
 937  * Returns the name of a given method in UTF format.
 938  * The result remains valid until JVM_ReleaseUTF is called.
 939  *
 940  * The caller must treat the string as a constant and not modify it
 941  * in any way.
 942  */
 943 JNIEXPORT const char * JNICALL
 944 JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index);
 945 
 946 /*
 947  * Returns the signature of a given method in UTF format.
 948  * The result remains valid until JVM_ReleaseUTF is called.
 949  *
 950  * The caller must treat the string as a constant and not modify it
 951  * in any way.
 952  */
 953 JNIEXPORT const char * JNICALL
 954 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index);
 955 
 956 /*
 957  * Returns the name of the field referred to at a given constant pool
 958  * index.
 959  *
 960  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 961  * is called.
 962  *
 963  * The caller must treat the string as a constant and not modify it
 964  * in any way.
 965  */
 966 JNIEXPORT const char * JNICALL
 967 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index);
 968 
 969 /*
 970  * Returns the name of the method referred to at a given constant pool
 971  * index.
 972  *
 973  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 974  * is called.
 975  *
 976  * The caller must treat the string as a constant and not modify it
 977  * in any way.
 978  */
 979 JNIEXPORT const char * JNICALL
 980 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index);
 981 
 982 /*
 983  * Returns the signature of the method referred to at a given constant pool
 984  * index.
 985  *
 986  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 987  * is called.
 988  *
 989  * The caller must treat the string as a constant and not modify it
 990  * in any way.
 991  */
 992 JNIEXPORT const char * JNICALL
 993 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index);
 994 
 995 /*
 996  * Returns the signature of the field referred to at a given constant pool
 997  * index.
 998  *
 999  * The result is in UTF format and remains valid until JVM_ReleaseUTF
1000  * is called.
1001  *
1002  * The caller must treat the string as a constant and not modify it
1003  * in any way.
1004  */
1005 JNIEXPORT const char * JNICALL
1006 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index);
1007 
1008 /*
1009  * Returns the class name referred to at a given constant pool index.
1010  *
1011  * The result is in UTF format and remains valid until JVM_ReleaseUTF
1012  * is called.
1013  *
1014  * The caller must treat the string as a constant and not modify it
1015  * in any way.
1016  */
1017 JNIEXPORT const char * JNICALL
1018 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index);
1019 
1020 /*
1021  * Returns the class name referred to at a given constant pool index.
1022  *
1023  * The constant pool entry must refer to a CONSTANT_Fieldref.
1024  *
1025  * The result is in UTF format and remains valid until JVM_ReleaseUTF
1026  * is called.
1027  *
1028  * The caller must treat the string as a constant and not modify it
1029  * in any way.
1030  */
1031 JNIEXPORT const char * JNICALL
1032 JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index);
1033 
1034 /*
1035  * Returns the class name referred to at a given constant pool index.
1036  *
1037  * The constant pool entry must refer to CONSTANT_Methodref or
1038  * CONSTANT_InterfaceMethodref.
1039  *
1040  * The result is in UTF format and remains valid until JVM_ReleaseUTF
1041  * is called.
1042  *
1043  * The caller must treat the string as a constant and not modify it
1044  * in any way.
1045  */
1046 JNIEXPORT const char * JNICALL
1047 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index);
1048 
1049 /*
1050  * Returns the modifiers of a field in calledClass. The field is
1051  * referred to in class cb at constant pool entry index.
1052  *
1053  * The caller must treat the string as a constant and not modify it
1054  * in any way.
1055  *
1056  * Returns -1 if the field does not exist in calledClass.
1057  */
1058 JNIEXPORT jint JNICALL
1059 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass);
1060 
1061 /*
1062  * Returns the modifiers of a method in calledClass. The method is
1063  * referred to in class cb at constant pool entry index.
1064  *
1065  * Returns -1 if the method does not exist in calledClass.
1066  */
1067 JNIEXPORT jint JNICALL
1068 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass);
1069 
1070 /*
1071  * Releases the UTF string obtained from the VM.
1072  */
1073 JNIEXPORT void JNICALL
1074 JVM_ReleaseUTF(const char *utf);
1075 
1076 /*
1077  * Compare if two classes are in the same package.
1078  */
1079 JNIEXPORT jboolean JNICALL
1080 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2);
1081 
1082 
1083 /*************************************************************************
1084  PART 3: I/O and Network Support
1085  ************************************************************************/
1086 
1087 /*
1088  * Convert a pathname into native format.  This function does syntactic
1089  * cleanup, such as removing redundant separator characters.  It modifies
1090  * the given pathname string in place.
1091  */
1092 JNIEXPORT char * JNICALL
1093 JVM_NativePath(char *);
1094 
1095 JNIEXPORT void * JNICALL
1096 JVM_RawMonitorCreate(void);
1097 
1098 JNIEXPORT void JNICALL
1099 JVM_RawMonitorDestroy(void *mon);
1100 
1101 JNIEXPORT jint JNICALL
1102 JVM_RawMonitorEnter(void *mon);
1103 
1104 JNIEXPORT void JNICALL
1105 JVM_RawMonitorExit(void *mon);
1106 
1107 /*
1108  * java.lang.management support
1109  */
1110 JNIEXPORT void* JNICALL
1111 JVM_GetManagement(jint version);
1112 
1113 /*
1114  * com.sun.tools.attach.VirtualMachine support
1115  *
1116  * Initialize the agent properties with the properties maintained in the VM.
1117  */
1118 JNIEXPORT jobject JNICALL
1119 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props);
1120 
1121 JNIEXPORT jstring JNICALL
1122 JVM_GetTemporaryDirectory(JNIEnv *env);
1123 
1124 /* Generics reflection support.
1125  *
1126  * Returns information about the given class's EnclosingMethod
1127  * attribute, if present, or null if the class had no enclosing
1128  * method.
1129  *
1130  * If non-null, the returned array contains three elements. Element 0
1131  * is the java.lang.Class of which the enclosing method is a member,
1132  * and elements 1 and 2 are the java.lang.Strings for the enclosing
1133  * method's name and descriptor, respectively.
1134  */
1135 JNIEXPORT jobjectArray JNICALL
1136 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass);
1137 
1138 /*
1139  * Virtual thread support.
1140  */
1141 JNIEXPORT void JNICALL
1142 JVM_VirtualThreadMountBegin(JNIEnv* env, jobject vthread, jboolean first_mount);
1143 
1144 JNIEXPORT void JNICALL
1145 JVM_VirtualThreadMountEnd(JNIEnv* env, jobject vthread, jboolean first_mount);
1146 
1147 JNIEXPORT void JNICALL
1148 JVM_VirtualThreadUnmountBegin(JNIEnv* env, jobject vthread, jboolean last_unmount);
1149 
1150 JNIEXPORT void JNICALL
1151 JVM_VirtualThreadUnmountEnd(JNIEnv* env, jobject vthread, jboolean last_unmount);
1152 
1153 JNIEXPORT void JNICALL
1154 JVM_VirtualThreadHideFrames(JNIEnv* env, jobject vthread, jboolean hide);
1155 
1156 /*
1157  * Core reflection support.
1158  */
1159 JNIEXPORT jint JNICALL
1160 JVM_GetClassFileVersion(JNIEnv *env, jclass current);
1161 
1162 /*
1163  * This structure is used by the launcher to get the default thread
1164  * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a
1165  * version of 1.1.  As it is not supported otherwise, it has been removed
1166  * from jni.h
1167  */
1168 typedef struct JDK1_1InitArgs {
1169     jint version;
1170 
1171     char **properties;
1172     jint checkSource;
1173     jint nativeStackSize;
1174     jint javaStackSize;
1175     jint minHeapSize;
1176     jint maxHeapSize;
1177     jint verifyMode;
1178     char *classpath;
1179 
1180     jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args);
1181     void (JNICALL *exit)(jint code);
1182     void (JNICALL *abort)(void);
1183 
1184     jint enableClassGC;
1185     jint enableVerboseGC;
1186     jint disableAsyncGC;
1187     jint verbose;
1188     jboolean debugging;
1189     jint debugPort;
1190 } JDK1_1InitArgs;
1191 
1192 
1193 #ifdef __cplusplus
1194 } /* extern "C" */
1195 
1196 #endif /* __cplusplus */
1197 
1198 #endif /* !_JAVASOFT_JVM_H_ */