1 /*
   2  * Copyright (c) 1997, 2009, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef _JAVASOFT_JVM_H_
  26 #define _JAVASOFT_JVM_H_
  27 
  28 // HotSpot integration note:
  29 //
  30 // This file and jvm.h used with the JDK are identical,
  31 // except for the three includes removed below and the
  32 // SUPPORT_OLD_REFLECTION sections cut out of the JDK's jvm.h.
  33 
  34 // #include <sys/stat.h>
  35 // #include "jni.h"
  36 // #include "jvm_md.h"
  37 
  38 
  39 #ifdef __cplusplus
  40 extern "C" {
  41 #endif
  42 
  43 /*
  44  * This file contains additional functions exported from the VM.
  45  * These functions are complementary to the standard JNI support.
  46  * There are three parts to this file:
  47  *
  48  * First, this file contains the VM-related functions needed by native
  49  * libraries in the standard Java API. For example, the java.lang.Object
  50  * class needs VM-level functions that wait for and notify monitors.
  51  *
  52  * Second, this file contains the functions and constant definitions
  53  * needed by the byte code verifier and class file format checker.
  54  * These functions allow the verifier and format checker to be written
  55  * in a VM-independent way.
  56  *
  57  * Third, this file contains various I/O and nerwork operations needed
  58  * by the standard Java I/O and network APIs.
  59  */
  60 
  61 /*
  62  * Bump the version number when either of the following happens:
  63  *
  64  * 1. There is a change in JVM_* functions.
  65  *
  66  * 2. There is a change in the contract between VM and Java classes.
  67  *    For example, if the VM relies on a new private field in Thread
  68  *    class.
  69  */
  70 
  71 #define JVM_INTERFACE_VERSION 4
  72 
  73 
  74 JNIEXPORT jint JNICALL
  75 JVM_GetInterfaceVersion(void);
  76 
  77 /*************************************************************************
  78  PART 1: Functions for Native Libraries
  79  ************************************************************************/
  80 /*
  81  * java.lang.Object
  82  */
  83 JNIEXPORT jint JNICALL
  84 JVM_IHashCode(JNIEnv *env, jobject obj);
  85 
  86 JNIEXPORT void JNICALL
  87 JVM_MonitorWait(JNIEnv *env, jobject obj, jlong ms);
  88 
  89 JNIEXPORT void JNICALL
  90 JVM_MonitorNotify(JNIEnv *env, jobject obj);
  91 
  92 JNIEXPORT void JNICALL
  93 JVM_MonitorNotifyAll(JNIEnv *env, jobject obj);
  94 
  95 JNIEXPORT jobject JNICALL
  96 JVM_Clone(JNIEnv *env, jobject obj);
  97 
  98 /*
  99  * java.lang.String
 100  */
 101 JNIEXPORT jstring JNICALL
 102 JVM_InternString(JNIEnv *env, jstring str);
 103 
 104 /*
 105  * java.lang.System
 106  */
 107 JNIEXPORT jlong JNICALL
 108 JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored);
 109 
 110 JNIEXPORT jlong JNICALL
 111 JVM_NanoTime(JNIEnv *env, jclass ignored);
 112 
 113 JNIEXPORT void JNICALL
 114 JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
 115               jobject dst, jint dst_pos, jint length);
 116 
 117 JNIEXPORT jobject JNICALL
 118 JVM_InitProperties(JNIEnv *env, jobject p);
 119 
 120 /*
 121  * java.io.File
 122  */
 123 JNIEXPORT void JNICALL
 124 JVM_OnExit(void (*func)(void));
 125 
 126 /*
 127  * java.lang.Runtime
 128  */
 129 JNIEXPORT void JNICALL
 130 JVM_Exit(jint code);
 131 
 132 JNIEXPORT void JNICALL
 133 JVM_Halt(jint code);
 134 
 135 JNIEXPORT void JNICALL
 136 JVM_GC(void);
 137 
 138 /* Returns the number of real-time milliseconds that have elapsed since the
 139  * least-recently-inspected heap object was last inspected by the garbage
 140  * collector.
 141  *
 142  * For simple stop-the-world collectors this value is just the time
 143  * since the most recent collection.  For generational collectors it is the
 144  * time since the oldest generation was most recently collected.  Other
 145  * collectors are free to return a pessimistic estimate of the elapsed time, or
 146  * simply the time since the last full collection was performed.
 147  *
 148  * Note that in the presence of reference objects, a given object that is no
 149  * longer strongly reachable may have to be inspected multiple times before it
 150  * can be reclaimed.
 151  */
 152 JNIEXPORT jlong JNICALL
 153 JVM_MaxObjectInspectionAge(void);
 154 
 155 JNIEXPORT void JNICALL
 156 JVM_TraceInstructions(jboolean on);
 157 
 158 JNIEXPORT void JNICALL
 159 JVM_TraceMethodCalls(jboolean on);
 160 
 161 JNIEXPORT jlong JNICALL
 162 JVM_TotalMemory(void);
 163 
 164 JNIEXPORT jlong JNICALL
 165 JVM_FreeMemory(void);
 166 
 167 JNIEXPORT jlong JNICALL
 168 JVM_MaxMemory(void);
 169 
 170 JNIEXPORT jint JNICALL
 171 JVM_ActiveProcessorCount(void);
 172 
 173 JNIEXPORT void * JNICALL
 174 JVM_LoadLibrary(const char *name);
 175 
 176 JNIEXPORT void JNICALL
 177 JVM_UnloadLibrary(void * handle);
 178 
 179 JNIEXPORT void * JNICALL
 180 JVM_FindLibraryEntry(void *handle, const char *name);
 181 
 182 JNIEXPORT jboolean JNICALL
 183 JVM_IsSupportedJNIVersion(jint version);
 184 
 185 /*
 186  * java.lang.Float and java.lang.Double
 187  */
 188 JNIEXPORT jboolean JNICALL
 189 JVM_IsNaN(jdouble d);
 190 
 191 /*
 192  * java.lang.Throwable
 193  */
 194 JNIEXPORT void JNICALL
 195 JVM_FillInStackTrace(JNIEnv *env, jobject throwable);
 196 
 197 JNIEXPORT void JNICALL
 198 JVM_PrintStackTrace(JNIEnv *env, jobject throwable, jobject printable);
 199 
 200 JNIEXPORT jint JNICALL
 201 JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable);
 202 
 203 JNIEXPORT jobject JNICALL
 204 JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index);
 205 
 206 /*
 207  * java.lang.Compiler
 208  */
 209 JNIEXPORT void JNICALL
 210 JVM_InitializeCompiler (JNIEnv *env, jclass compCls);
 211 
 212 JNIEXPORT jboolean JNICALL
 213 JVM_IsSilentCompiler(JNIEnv *env, jclass compCls);
 214 
 215 JNIEXPORT jboolean JNICALL
 216 JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls);
 217 
 218 JNIEXPORT jboolean JNICALL
 219 JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname);
 220 
 221 JNIEXPORT jobject JNICALL
 222 JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg);
 223 
 224 JNIEXPORT void JNICALL
 225 JVM_EnableCompiler(JNIEnv *env, jclass compCls);
 226 
 227 JNIEXPORT void JNICALL
 228 JVM_DisableCompiler(JNIEnv *env, jclass compCls);
 229 
 230 /*
 231  * java.lang.Thread
 232  */
 233 JNIEXPORT void JNICALL
 234 JVM_StartThread(JNIEnv *env, jobject thread);
 235 
 236 JNIEXPORT void JNICALL
 237 JVM_StopThread(JNIEnv *env, jobject thread, jobject exception);
 238 
 239 JNIEXPORT jboolean JNICALL
 240 JVM_IsThreadAlive(JNIEnv *env, jobject thread);
 241 
 242 JNIEXPORT void JNICALL
 243 JVM_SuspendThread(JNIEnv *env, jobject thread);
 244 
 245 JNIEXPORT void JNICALL
 246 JVM_ResumeThread(JNIEnv *env, jobject thread);
 247 
 248 JNIEXPORT void JNICALL
 249 JVM_SetThreadPriority(JNIEnv *env, jobject thread, jint prio);
 250 
 251 JNIEXPORT void JNICALL
 252 JVM_Yield(JNIEnv *env, jclass threadClass);
 253 
 254 JNIEXPORT void JNICALL
 255 JVM_Sleep(JNIEnv *env, jclass threadClass, jlong millis);
 256 
 257 JNIEXPORT jobject JNICALL
 258 JVM_CurrentThread(JNIEnv *env, jclass threadClass);
 259 
 260 JNIEXPORT jint JNICALL
 261 JVM_CountStackFrames(JNIEnv *env, jobject thread);
 262 
 263 JNIEXPORT void JNICALL
 264 JVM_Interrupt(JNIEnv *env, jobject thread);
 265 
 266 JNIEXPORT jboolean JNICALL
 267 JVM_IsInterrupted(JNIEnv *env, jobject thread, jboolean clearInterrupted);
 268 
 269 JNIEXPORT jboolean JNICALL
 270 JVM_HoldsLock(JNIEnv *env, jclass threadClass, jobject obj);
 271 
 272 JNIEXPORT void JNICALL
 273 JVM_DumpAllStacks(JNIEnv *env, jclass unused);
 274 
 275 JNIEXPORT jobjectArray JNICALL
 276 JVM_GetAllThreads(JNIEnv *env, jclass dummy);
 277 
 278 /* getStackTrace() and getAllStackTraces() method */
 279 JNIEXPORT jobjectArray JNICALL
 280 JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads);
 281 
 282 /*
 283  * java.lang.SecurityManager
 284  */
 285 JNIEXPORT jclass JNICALL
 286 JVM_CurrentLoadedClass(JNIEnv *env);
 287 
 288 JNIEXPORT jobject JNICALL
 289 JVM_CurrentClassLoader(JNIEnv *env);
 290 
 291 JNIEXPORT jobjectArray JNICALL
 292 JVM_GetClassContext(JNIEnv *env);
 293 
 294 JNIEXPORT jint JNICALL
 295 JVM_ClassDepth(JNIEnv *env, jstring name);
 296 
 297 JNIEXPORT jint JNICALL
 298 JVM_ClassLoaderDepth(JNIEnv *env);
 299 
 300 /*
 301  * java.lang.Package
 302  */
 303 JNIEXPORT jstring JNICALL
 304 JVM_GetSystemPackage(JNIEnv *env, jstring name);
 305 
 306 JNIEXPORT jobjectArray JNICALL
 307 JVM_GetSystemPackages(JNIEnv *env);
 308 
 309 /*
 310  * java.io.ObjectInputStream
 311  */
 312 JNIEXPORT jobject JNICALL
 313 JVM_AllocateNewObject(JNIEnv *env, jobject obj, jclass currClass,
 314                       jclass initClass);
 315 
 316 JNIEXPORT jobject JNICALL
 317 JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass,
 318                      jint length);
 319 
 320 JNIEXPORT jobject JNICALL
 321 JVM_LatestUserDefinedLoader(JNIEnv *env);
 322 
 323 /*
 324  * This function has been deprecated and should not be considered
 325  * part of the specified JVM interface.
 326  */
 327 JNIEXPORT jclass JNICALL
 328 JVM_LoadClass0(JNIEnv *env, jobject obj, jclass currClass,
 329                jstring currClassName);
 330 
 331 /*
 332  * java.lang.reflect.Array
 333  */
 334 JNIEXPORT jint JNICALL
 335 JVM_GetArrayLength(JNIEnv *env, jobject arr);
 336 
 337 JNIEXPORT jobject JNICALL
 338 JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index);
 339 
 340 JNIEXPORT jvalue JNICALL
 341 JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode);
 342 
 343 JNIEXPORT void JNICALL
 344 JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val);
 345 
 346 JNIEXPORT void JNICALL
 347 JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v,
 348                              unsigned char vCode);
 349 
 350 JNIEXPORT jobject JNICALL
 351 JVM_NewArray(JNIEnv *env, jclass eltClass, jint length);
 352 
 353 JNIEXPORT jobject JNICALL
 354 JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim);
 355 
 356 /*
 357  * java.lang.Class and java.lang.ClassLoader
 358  */
 359 /*
 360  * Returns the class in which the code invoking the native method
 361  * belongs.
 362  *
 363  * Note that in JDK 1.1, native methods did not create a frame.
 364  * In 1.2, they do. Therefore native methods like Class.forName
 365  * can no longer look at the current frame for the caller class.
 366  */
 367 JNIEXPORT jclass JNICALL
 368 JVM_GetCallerClass(JNIEnv *env, int n);
 369 
 370 /*
 371  * Find primitive classes
 372  * utf: class name
 373  */
 374 JNIEXPORT jclass JNICALL
 375 JVM_FindPrimitiveClass(JNIEnv *env, const char *utf);
 376 
 377 /*
 378  * Link the class
 379  */
 380 JNIEXPORT void JNICALL
 381 JVM_ResolveClass(JNIEnv *env, jclass cls);
 382 
 383 /*
 384  * Find a class from a given class loader. Throw ClassNotFoundException
 385  * or NoClassDefFoundError depending on the value of the last
 386  * argument.
 387  */
 388 JNIEXPORT jclass JNICALL
 389 JVM_FindClassFromClassLoader(JNIEnv *env, const char *name, jboolean init,
 390                              jobject loader, jboolean throwError);
 391 
 392 /*
 393  * Find a class from a boot class loader. Returns NULL if class not found.
 394  */
 395 JNIEXPORT jclass JNICALL
 396 JVM_FindClassFromBootLoader(JNIEnv *env, const char *name);
 397 
 398 /*
 399  * Find a class from a given class.
 400  */
 401 JNIEXPORT jclass JNICALL
 402 JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init,
 403                              jclass from);
 404 
 405 /* Find a loaded class cached by the VM */
 406 JNIEXPORT jclass JNICALL
 407 JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name);
 408 
 409 /* Define a class */
 410 JNIEXPORT jclass JNICALL
 411 JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf,
 412                 jsize len, jobject pd);
 413 
 414 /* Define a class with a source (added in JDK1.5) */
 415 JNIEXPORT jclass JNICALL
 416 JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
 417                           const jbyte *buf, jsize len, jobject pd,
 418                           const char *source);
 419 
 420 /* Define a class with a source with conditional verification (added HSX 14)
 421  * -Xverify:all will verify anyway, -Xverify:none will not verify,
 422  * -Xverify:remote (default) will obey this conditional
 423  * i.e. true = should_verify_class
 424  */
 425 JNIEXPORT jclass JNICALL
 426 JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
 427                               jobject loader, const jbyte *buf,
 428                               jsize len, jobject pd, const char *source,
 429                               jboolean verify);
 430 
 431 /* Define a class with a source (MLVM) */
 432 JNIEXPORT jclass JNICALL
 433 JVM_DefineClassWithCP(JNIEnv *env, const char *name, jobject loader,
 434                       const jbyte *buf, jsize len, jobject pd,
 435                       const char *source,
 436                       // same args as JVM_DefineClassWithSource to this point
 437                       jobjectArray constants);
 438 
 439 /*
 440  * Reflection support functions
 441  */
 442 
 443 JNIEXPORT jstring JNICALL
 444 JVM_GetClassName(JNIEnv *env, jclass cls);
 445 
 446 JNIEXPORT jobjectArray JNICALL
 447 JVM_GetClassInterfaces(JNIEnv *env, jclass cls);
 448 
 449 JNIEXPORT jobject JNICALL
 450 JVM_GetClassLoader(JNIEnv *env, jclass cls);
 451 
 452 JNIEXPORT jboolean JNICALL
 453 JVM_IsInterface(JNIEnv *env, jclass cls);
 454 
 455 JNIEXPORT jobjectArray JNICALL
 456 JVM_GetClassSigners(JNIEnv *env, jclass cls);
 457 
 458 JNIEXPORT void JNICALL
 459 JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers);
 460 
 461 JNIEXPORT jobject JNICALL
 462 JVM_GetProtectionDomain(JNIEnv *env, jclass cls);
 463 
 464 JNIEXPORT void JNICALL
 465 JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain);
 466 
 467 JNIEXPORT jboolean JNICALL
 468 JVM_IsArrayClass(JNIEnv *env, jclass cls);
 469 
 470 JNIEXPORT jboolean JNICALL
 471 JVM_IsPrimitiveClass(JNIEnv *env, jclass cls);
 472 
 473 JNIEXPORT jclass JNICALL
 474 JVM_GetComponentType(JNIEnv *env, jclass cls);
 475 
 476 JNIEXPORT jint JNICALL
 477 JVM_GetClassModifiers(JNIEnv *env, jclass cls);
 478 
 479 JNIEXPORT jobjectArray JNICALL
 480 JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass);
 481 
 482 JNIEXPORT jclass JNICALL
 483 JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass);
 484 
 485 /* Generics support (JDK 1.5) */
 486 JNIEXPORT jstring JNICALL
 487 JVM_GetClassSignature(JNIEnv *env, jclass cls);
 488 
 489 /* Annotations support (JDK 1.5) */
 490 JNIEXPORT jbyteArray JNICALL
 491 JVM_GetClassAnnotations(JNIEnv *env, jclass cls);
 492 
 493 /* Annotations support (JDK 1.6) */
 494 
 495 // field is a handle to a java.lang.reflect.Field object
 496 JNIEXPORT jbyteArray JNICALL
 497 JVM_GetFieldAnnotations(JNIEnv *env, jobject field);
 498 
 499 // method is a handle to a java.lang.reflect.Method object
 500 JNIEXPORT jbyteArray JNICALL
 501 JVM_GetMethodAnnotations(JNIEnv *env, jobject method);
 502 
 503 // method is a handle to a java.lang.reflect.Method object
 504 JNIEXPORT jbyteArray JNICALL
 505 JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method);
 506 
 507 // method is a handle to a java.lang.reflect.Method object
 508 JNIEXPORT jbyteArray JNICALL
 509 JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method);
 510 
 511 
 512 /*
 513  * New (JDK 1.4) reflection implementation
 514  */
 515 
 516 JNIEXPORT jobjectArray JNICALL
 517 JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 518 
 519 JNIEXPORT jobjectArray JNICALL
 520 JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 521 
 522 JNIEXPORT jobjectArray JNICALL
 523 JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly);
 524 
 525 /* Differs from JVM_GetClassModifiers in treatment of inner classes.
 526    This returns the access flags for the class as specified in the
 527    class file rather than searching the InnerClasses attribute (if
 528    present) to find the source-level access flags. Only the values of
 529    the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
 530    valid. */
 531 JNIEXPORT jint JNICALL
 532 JVM_GetClassAccessFlags(JNIEnv *env, jclass cls);
 533 
 534 /*
 535  * Constant pool access; currently used to implement reflective access to annotations (JDK 1.5)
 536  */
 537 
 538 JNIEXPORT jobject JNICALL
 539 JVM_GetClassConstantPool(JNIEnv *env, jclass cls);
 540 
 541 JNIEXPORT jint JNICALL JVM_ConstantPoolGetSize
 542 (JNIEnv *env, jobject unused, jobject jcpool);
 543 
 544 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAt
 545 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 546 
 547 JNIEXPORT jclass JNICALL JVM_ConstantPoolGetClassAtIfLoaded
 548 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 549 
 550 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAt
 551 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 552 
 553 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetMethodAtIfLoaded
 554 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 555 
 556 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAt
 557 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 558 
 559 JNIEXPORT jobject JNICALL JVM_ConstantPoolGetFieldAtIfLoaded
 560 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 561 
 562 JNIEXPORT jobjectArray JNICALL JVM_ConstantPoolGetMemberRefInfoAt
 563 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 564 
 565 JNIEXPORT jint JNICALL JVM_ConstantPoolGetIntAt
 566 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 567 
 568 JNIEXPORT jlong JNICALL JVM_ConstantPoolGetLongAt
 569 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 570 
 571 JNIEXPORT jfloat JNICALL JVM_ConstantPoolGetFloatAt
 572 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 573 
 574 JNIEXPORT jdouble JNICALL JVM_ConstantPoolGetDoubleAt
 575 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 576 
 577 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetStringAt
 578 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 579 
 580 JNIEXPORT jstring JNICALL JVM_ConstantPoolGetUTF8At
 581 (JNIEnv *env, jobject unused, jobject jcpool, jint index);
 582 
 583 /*
 584  * java.security.*
 585  */
 586 
 587 JNIEXPORT jobject JNICALL
 588 JVM_DoPrivileged(JNIEnv *env, jclass cls,
 589                  jobject action, jobject context, jboolean wrapException);
 590 
 591 JNIEXPORT jobject JNICALL
 592 JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls);
 593 
 594 JNIEXPORT jobject JNICALL
 595 JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls);
 596 
 597 /*
 598  * Signal support, used to implement the shutdown sequence.  Every VM must
 599  * support JVM_SIGINT and JVM_SIGTERM, raising the former for user interrupts
 600  * (^C) and the latter for external termination (kill, system shutdown, etc.).
 601  * Other platform-dependent signal values may also be supported.
 602  */
 603 
 604 JNIEXPORT void * JNICALL
 605 JVM_RegisterSignal(jint sig, void *handler);
 606 
 607 JNIEXPORT jboolean JNICALL
 608 JVM_RaiseSignal(jint sig);
 609 
 610 JNIEXPORT jint JNICALL
 611 JVM_FindSignal(const char *name);
 612 
 613 /*
 614  * Retrieve the assertion directives for the specified class.
 615  */
 616 JNIEXPORT jboolean JNICALL
 617 JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls);
 618 
 619 /*
 620  * Retrieve the assertion directives from the VM.
 621  */
 622 JNIEXPORT jobject JNICALL
 623 JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused);
 624 
 625 /*
 626  * sun.misc.AtomicLong
 627  */
 628 JNIEXPORT jboolean JNICALL
 629 JVM_SupportsCX8(void);
 630 
 631 JNIEXPORT jboolean JNICALL
 632 JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fldID, jlong oldVal, jlong newVal);
 633 
 634 /*
 635  * com.sun.dtrace.jsdt support
 636  */
 637 
 638 #define JVM_TRACING_DTRACE_VERSION 1
 639 
 640 /*
 641  * Structure to pass one probe description to JVM.
 642  *
 643  * The VM will overwrite the definition of the referenced method with
 644  * code that will fire the probe.
 645  */
 646 typedef struct {
 647     jmethodID method;
 648     jstring   function;
 649     jstring   name;
 650     void*     reserved[4];     // for future use
 651 } JVM_DTraceProbe;
 652 
 653 /**
 654  * Encapsulates the stability ratings for a DTrace provider field
 655  */
 656 typedef struct {
 657     jint nameStability;
 658     jint dataStability;
 659     jint dependencyClass;
 660 } JVM_DTraceInterfaceAttributes;
 661 
 662 /*
 663  * Structure to pass one provider description to JVM
 664  */
 665 typedef struct {
 666     jstring                       name;
 667     JVM_DTraceProbe*              probes;
 668     jint                          probe_count;
 669     JVM_DTraceInterfaceAttributes providerAttributes;
 670     JVM_DTraceInterfaceAttributes moduleAttributes;
 671     JVM_DTraceInterfaceAttributes functionAttributes;
 672     JVM_DTraceInterfaceAttributes nameAttributes;
 673     JVM_DTraceInterfaceAttributes argsAttributes;
 674     void*                         reserved[4]; // for future use
 675 } JVM_DTraceProvider;
 676 
 677 /*
 678  * Get the version number the JVM was built with
 679  */
 680 JNIEXPORT jint JNICALL
 681 JVM_DTraceGetVersion(JNIEnv* env);
 682 
 683 /*
 684  * Register new probe with given signature, return global handle
 685  *
 686  * The version passed in is the version that the library code was
 687  * built with.
 688  */
 689 JNIEXPORT jlong JNICALL
 690 JVM_DTraceActivate(JNIEnv* env, jint version, jstring module_name,
 691   jint providers_count, JVM_DTraceProvider* providers);
 692 
 693 /*
 694  * Check JSDT probe
 695  */
 696 JNIEXPORT jboolean JNICALL
 697 JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method);
 698 
 699 /*
 700  * Destroy custom DOF
 701  */
 702 JNIEXPORT void JNICALL
 703 JVM_DTraceDispose(JNIEnv* env, jlong handle);
 704 
 705 /*
 706  * Check to see if DTrace is supported by OS
 707  */
 708 JNIEXPORT jboolean JNICALL
 709 JVM_DTraceIsSupported(JNIEnv* env);
 710 
 711 /*************************************************************************
 712  PART 2: Support for the Verifier and Class File Format Checker
 713  ************************************************************************/
 714 /*
 715  * Return the class name in UTF format. The result is valid
 716  * until JVM_ReleaseUTf is called.
 717  *
 718  * The caller must treat the string as a constant and not modify it
 719  * in any way.
 720  */
 721 JNIEXPORT const char * JNICALL
 722 JVM_GetClassNameUTF(JNIEnv *env, jclass cb);
 723 
 724 /*
 725  * Returns the constant pool types in the buffer provided by "types."
 726  */
 727 JNIEXPORT void JNICALL
 728 JVM_GetClassCPTypes(JNIEnv *env, jclass cb, unsigned char *types);
 729 
 730 /*
 731  * Returns the number of Constant Pool entries.
 732  */
 733 JNIEXPORT jint JNICALL
 734 JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cb);
 735 
 736 /*
 737  * Returns the number of *declared* fields or methods.
 738  */
 739 JNIEXPORT jint JNICALL
 740 JVM_GetClassFieldsCount(JNIEnv *env, jclass cb);
 741 
 742 JNIEXPORT jint JNICALL
 743 JVM_GetClassMethodsCount(JNIEnv *env, jclass cb);
 744 
 745 /*
 746  * Returns the CP indexes of exceptions raised by a given method.
 747  * Places the result in the given buffer.
 748  *
 749  * The method is identified by method_index.
 750  */
 751 JNIEXPORT void JNICALL
 752 JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cb, jint method_index,
 753                                 unsigned short *exceptions);
 754 /*
 755  * Returns the number of exceptions raised by a given method.
 756  * The method is identified by method_index.
 757  */
 758 JNIEXPORT jint JNICALL
 759 JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cb, jint method_index);
 760 
 761 /*
 762  * Returns the byte code sequence of a given method.
 763  * Places the result in the given buffer.
 764  *
 765  * The method is identified by method_index.
 766  */
 767 JNIEXPORT void JNICALL
 768 JVM_GetMethodIxByteCode(JNIEnv *env, jclass cb, jint method_index,
 769                         unsigned char *code);
 770 
 771 /*
 772  * Returns the length of the byte code sequence of a given method.
 773  * The method is identified by method_index.
 774  */
 775 JNIEXPORT jint JNICALL
 776 JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cb, jint method_index);
 777 
 778 /*
 779  * A structure used to a capture exception table entry in a Java method.
 780  */
 781 typedef struct {
 782     jint start_pc;
 783     jint end_pc;
 784     jint handler_pc;
 785     jint catchType;
 786 } JVM_ExceptionTableEntryType;
 787 
 788 /*
 789  * Returns the exception table entry at entry_index of a given method.
 790  * Places the result in the given buffer.
 791  *
 792  * The method is identified by method_index.
 793  */
 794 JNIEXPORT void JNICALL
 795 JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cb, jint method_index,
 796                                    jint entry_index,
 797                                    JVM_ExceptionTableEntryType *entry);
 798 
 799 /*
 800  * Returns the length of the exception table of a given method.
 801  * The method is identified by method_index.
 802  */
 803 JNIEXPORT jint JNICALL
 804 JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cb, int index);
 805 
 806 /*
 807  * Returns the modifiers of a given field.
 808  * The field is identified by field_index.
 809  */
 810 JNIEXPORT jint JNICALL
 811 JVM_GetFieldIxModifiers(JNIEnv *env, jclass cb, int index);
 812 
 813 /*
 814  * Returns the modifiers of a given method.
 815  * The method is identified by method_index.
 816  */
 817 JNIEXPORT jint JNICALL
 818 JVM_GetMethodIxModifiers(JNIEnv *env, jclass cb, int index);
 819 
 820 /*
 821  * Returns the number of local variables of a given method.
 822  * The method is identified by method_index.
 823  */
 824 JNIEXPORT jint JNICALL
 825 JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cb, int index);
 826 
 827 /*
 828  * Returns the number of arguments (including this pointer) of a given method.
 829  * The method is identified by method_index.
 830  */
 831 JNIEXPORT jint JNICALL
 832 JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cb, int index);
 833 
 834 /*
 835  * Returns the maximum amount of stack (in words) used by a given method.
 836  * The method is identified by method_index.
 837  */
 838 JNIEXPORT jint JNICALL
 839 JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cb, int index);
 840 
 841 /*
 842  * Is a given method a constructor.
 843  * The method is identified by method_index.
 844  */
 845 JNIEXPORT jboolean JNICALL
 846 JVM_IsConstructorIx(JNIEnv *env, jclass cb, int index);
 847 
 848 /*
 849  * Returns the name of a given method in UTF format.
 850  * The result remains valid until JVM_ReleaseUTF 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_GetMethodIxNameUTF(JNIEnv *env, jclass cb, jint index);
 857 
 858 /*
 859  * Returns the signature of a given method in UTF format.
 860  * The result remains valid until JVM_ReleaseUTF is called.
 861  *
 862  * The caller must treat the string as a constant and not modify it
 863  * in any way.
 864  */
 865 JNIEXPORT const char * JNICALL
 866 JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cb, jint index);
 867 
 868 /*
 869  * Returns the name of the field refered to at a given constant pool
 870  * index.
 871  *
 872  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 873  * is called.
 874  *
 875  * The caller must treat the string as a constant and not modify it
 876  * in any way.
 877  */
 878 JNIEXPORT const char * JNICALL
 879 JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cb, jint index);
 880 
 881 /*
 882  * Returns the name of the method refered to at a given constant pool
 883  * index.
 884  *
 885  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 886  * is called.
 887  *
 888  * The caller must treat the string as a constant and not modify it
 889  * in any way.
 890  */
 891 JNIEXPORT const char * JNICALL
 892 JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cb, jint index);
 893 
 894 /*
 895  * Returns the signature of the method refered to at a given constant pool
 896  * index.
 897  *
 898  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 899  * is called.
 900  *
 901  * The caller must treat the string as a constant and not modify it
 902  * in any way.
 903  */
 904 JNIEXPORT const char * JNICALL
 905 JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cb, jint index);
 906 
 907 /*
 908  * Returns the signature of the field refered to at a given constant pool
 909  * index.
 910  *
 911  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 912  * is called.
 913  *
 914  * The caller must treat the string as a constant and not modify it
 915  * in any way.
 916  */
 917 JNIEXPORT const char * JNICALL
 918 JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cb, jint index);
 919 
 920 /*
 921  * Returns the class name refered to at a given constant pool 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  */
 929 JNIEXPORT const char * JNICALL
 930 JVM_GetCPClassNameUTF(JNIEnv *env, jclass cb, jint index);
 931 
 932 /*
 933  * Returns the class name refered to at a given constant pool index.
 934  *
 935  * The constant pool entry must refer to a CONSTANT_Fieldref.
 936  *
 937  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 938  * 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_GetCPFieldClassNameUTF(JNIEnv *env, jclass cb, jint index);
 945 
 946 /*
 947  * Returns the class name refered to at a given constant pool index.
 948  *
 949  * The constant pool entry must refer to CONSTANT_Methodref or
 950  * CONSTANT_InterfaceMethodref.
 951  *
 952  * The result is in UTF format and remains valid until JVM_ReleaseUTF
 953  * is called.
 954  *
 955  * The caller must treat the string as a constant and not modify it
 956  * in any way.
 957  */
 958 JNIEXPORT const char * JNICALL
 959 JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cb, jint index);
 960 
 961 /*
 962  * Returns the modifiers of a field in calledClass. The field is
 963  * referred to in class cb at constant pool entry index.
 964  *
 965  * The caller must treat the string as a constant and not modify it
 966  * in any way.
 967  *
 968  * Returns -1 if the field does not exist in calledClass.
 969  */
 970 JNIEXPORT jint JNICALL
 971 JVM_GetCPFieldModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass);
 972 
 973 /*
 974  * Returns the modifiers of a method in calledClass. The method is
 975  * referred to in class cb at constant pool entry index.
 976  *
 977  * Returns -1 if the method does not exist in calledClass.
 978  */
 979 JNIEXPORT jint JNICALL
 980 JVM_GetCPMethodModifiers(JNIEnv *env, jclass cb, int index, jclass calledClass);
 981 
 982 /*
 983  * Releases the UTF string obtained from the VM.
 984  */
 985 JNIEXPORT void JNICALL
 986 JVM_ReleaseUTF(const char *utf);
 987 
 988 /*
 989  * Compare if two classes are in the same package.
 990  */
 991 JNIEXPORT jboolean JNICALL
 992 JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2);
 993 
 994 /* Constants in class files */
 995 
 996 #define JVM_ACC_PUBLIC        0x0001  /* visible to everyone */
 997 #define JVM_ACC_PRIVATE       0x0002  /* visible only to the defining class */
 998 #define JVM_ACC_PROTECTED     0x0004  /* visible to subclasses */
 999 #define JVM_ACC_STATIC        0x0008  /* instance variable is static */
1000 #define JVM_ACC_FINAL         0x0010  /* no further subclassing, overriding */
1001 #define JVM_ACC_SYNCHRONIZED  0x0020  /* wrap method call in monitor lock */
1002 #define JVM_ACC_SUPER         0x0020  /* funky handling of invokespecial */
1003 #define JVM_ACC_VOLATILE      0x0040  /* can not cache in registers */
1004 #define JVM_ACC_BRIDGE        0x0040  /* bridge method generated by compiler */
1005 #define JVM_ACC_TRANSIENT     0x0080  /* not persistent */
1006 #define JVM_ACC_VARARGS       0x0080  /* method declared with variable number of args */
1007 #define JVM_ACC_NATIVE        0x0100  /* implemented in C */
1008 #define JVM_ACC_INTERFACE     0x0200  /* class is an interface */
1009 #define JVM_ACC_ABSTRACT      0x0400  /* no definition provided */
1010 #define JVM_ACC_STRICT        0x0800  /* strict floating point */
1011 #define JVM_ACC_SYNTHETIC     0x1000  /* compiler-generated class, method or field */
1012 #define JVM_ACC_ANNOTATION    0x2000  /* annotation type */
1013 #define JVM_ACC_ENUM          0x4000  /* field is declared as element of enum */
1014 
1015 #define JVM_ACC_PUBLIC_BIT        0
1016 #define JVM_ACC_PRIVATE_BIT       1
1017 #define JVM_ACC_PROTECTED_BIT     2
1018 #define JVM_ACC_STATIC_BIT        3
1019 #define JVM_ACC_FINAL_BIT         4
1020 #define JVM_ACC_SYNCHRONIZED_BIT  5
1021 #define JVM_ACC_SUPER_BIT         5
1022 #define JVM_ACC_VOLATILE_BIT      6
1023 #define JVM_ACC_BRIDGE_BIT        6
1024 #define JVM_ACC_TRANSIENT_BIT     7
1025 #define JVM_ACC_VARARGS_BIT       7
1026 #define JVM_ACC_NATIVE_BIT        8
1027 #define JVM_ACC_INTERFACE_BIT     9
1028 #define JVM_ACC_ABSTRACT_BIT      10
1029 #define JVM_ACC_STRICT_BIT        11
1030 #define JVM_ACC_SYNTHETIC_BIT     12
1031 #define JVM_ACC_ANNOTATION_BIT    13
1032 #define JVM_ACC_ENUM_BIT          14
1033 
1034 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/utilities/ConstantTag.java
1035 enum {
1036     JVM_CONSTANT_Utf8 = 1,
1037     JVM_CONSTANT_Unicode,               /* unused */
1038     JVM_CONSTANT_Integer,
1039     JVM_CONSTANT_Float,
1040     JVM_CONSTANT_Long,
1041     JVM_CONSTANT_Double,
1042     JVM_CONSTANT_Class,
1043     JVM_CONSTANT_String,
1044     JVM_CONSTANT_Fieldref,
1045     JVM_CONSTANT_Methodref,
1046     JVM_CONSTANT_InterfaceMethodref,
1047     JVM_CONSTANT_NameAndType,
1048     JVM_CONSTANT_MethodHandle           = 15,  // JSR 292
1049     JVM_CONSTANT_MethodType             = 16,  // JSR 292
1050     JVM_CONSTANT_InvokeDynamic          = 17  // JSR 292
1051 };
1052 
1053 /* JVM_CONSTANT_MethodHandle subtypes */
1054 enum {
1055     JVM_REF_getField                = 1,
1056     JVM_REF_getStatic               = 2,
1057     JVM_REF_putField                = 3,
1058     JVM_REF_putStatic               = 4,
1059     JVM_REF_invokeVirtual           = 5,
1060     JVM_REF_invokeStatic            = 6,
1061     JVM_REF_invokeSpecial           = 7,
1062     JVM_REF_newInvokeSpecial        = 8,
1063     JVM_REF_invokeInterface         = 9
1064 };
1065 
1066 /* Used in the newarray instruction. */
1067 
1068 #define JVM_T_BOOLEAN 4
1069 #define JVM_T_CHAR    5
1070 #define JVM_T_FLOAT   6
1071 #define JVM_T_DOUBLE  7
1072 #define JVM_T_BYTE    8
1073 #define JVM_T_SHORT   9
1074 #define JVM_T_INT    10
1075 #define JVM_T_LONG   11
1076 
1077 /* JVM method signatures */
1078 
1079 #define JVM_SIGNATURE_ARRAY             '['
1080 #define JVM_SIGNATURE_BYTE              'B'
1081 #define JVM_SIGNATURE_CHAR              'C'
1082 #define JVM_SIGNATURE_CLASS             'L'
1083 #define JVM_SIGNATURE_ENDCLASS          ';'
1084 #define JVM_SIGNATURE_ENUM              'E'
1085 #define JVM_SIGNATURE_FLOAT             'F'
1086 #define JVM_SIGNATURE_DOUBLE            'D'
1087 #define JVM_SIGNATURE_FUNC              '('
1088 #define JVM_SIGNATURE_ENDFUNC           ')'
1089 #define JVM_SIGNATURE_INT               'I'
1090 #define JVM_SIGNATURE_LONG              'J'
1091 #define JVM_SIGNATURE_SHORT             'S'
1092 #define JVM_SIGNATURE_VOID              'V'
1093 #define JVM_SIGNATURE_BOOLEAN           'Z'
1094 
1095 /*
1096  * A function defined by the byte-code verifier and called by the VM.
1097  * This is not a function implemented in the VM.
1098  *
1099  * Returns JNI_FALSE if verification fails. A detailed error message
1100  * will be places in msg_buf, whose length is specified by buf_len.
1101  */
1102 typedef jboolean (*verifier_fn_t)(JNIEnv *env,
1103                                   jclass cb,
1104                                   char * msg_buf,
1105                                   jint buf_len);
1106 
1107 
1108 /*
1109  * Support for a VM-independent class format checker.
1110  */
1111 typedef struct {
1112     unsigned long code;    /* byte code */
1113     unsigned long excs;    /* exceptions */
1114     unsigned long etab;    /* catch table */
1115     unsigned long lnum;    /* line number */
1116     unsigned long lvar;    /* local vars */
1117 } method_size_info;
1118 
1119 typedef struct {
1120     unsigned int constants;    /* constant pool */
1121     unsigned int fields;
1122     unsigned int methods;
1123     unsigned int interfaces;
1124     unsigned int fields2;      /* number of static 2-word fields */
1125     unsigned int innerclasses; /* # of records in InnerClasses attr */
1126 
1127     method_size_info clinit;   /* memory used in clinit */
1128     method_size_info main;     /* used everywhere else */
1129 } class_size_info;
1130 
1131 /*
1132  * Functions defined in libjava.so to perform string conversions.
1133  *
1134  */
1135 
1136 typedef jstring (*to_java_string_fn_t)(JNIEnv *env, char *str);
1137 
1138 typedef char *(*to_c_string_fn_t)(JNIEnv *env, jstring s, jboolean *b);
1139 
1140 /* This is the function defined in libjava.so that performs class
1141  * format checks. This functions fills in size information about
1142  * the class file and returns:
1143  *
1144  *   0: good
1145  *  -1: out of memory
1146  *  -2: bad format
1147  *  -3: unsupported version
1148  *  -4: bad class name
1149  */
1150 
1151 typedef jint (*check_format_fn_t)(char *class_name,
1152                                   unsigned char *data,
1153                                   unsigned int data_size,
1154                                   class_size_info *class_size,
1155                                   char *message_buffer,
1156                                   jint buffer_length,
1157                                   jboolean measure_only,
1158                                   jboolean check_relaxed);
1159 
1160 #define JVM_RECOGNIZED_CLASS_MODIFIERS (JVM_ACC_PUBLIC | \
1161                                         JVM_ACC_FINAL | \
1162                                         JVM_ACC_SUPER | \
1163                                         JVM_ACC_INTERFACE | \
1164                                         JVM_ACC_ABSTRACT | \
1165                                         JVM_ACC_ANNOTATION | \
1166                                         JVM_ACC_ENUM | \
1167                                         JVM_ACC_SYNTHETIC)
1168 
1169 #define JVM_RECOGNIZED_FIELD_MODIFIERS (JVM_ACC_PUBLIC | \
1170                                         JVM_ACC_PRIVATE | \
1171                                         JVM_ACC_PROTECTED | \
1172                                         JVM_ACC_STATIC | \
1173                                         JVM_ACC_FINAL | \
1174                                         JVM_ACC_VOLATILE | \
1175                                         JVM_ACC_TRANSIENT | \
1176                                         JVM_ACC_ENUM | \
1177                                         JVM_ACC_SYNTHETIC)
1178 
1179 #define JVM_RECOGNIZED_METHOD_MODIFIERS (JVM_ACC_PUBLIC | \
1180                                          JVM_ACC_PRIVATE | \
1181                                          JVM_ACC_PROTECTED | \
1182                                          JVM_ACC_STATIC | \
1183                                          JVM_ACC_FINAL | \
1184                                          JVM_ACC_SYNCHRONIZED | \
1185                                          JVM_ACC_BRIDGE | \
1186                                          JVM_ACC_VARARGS | \
1187                                          JVM_ACC_NATIVE | \
1188                                          JVM_ACC_ABSTRACT | \
1189                                          JVM_ACC_STRICT | \
1190                                          JVM_ACC_SYNTHETIC)
1191 
1192 /*
1193  * This is the function defined in libjava.so to perform path
1194  * canonicalization. VM call this function before opening jar files
1195  * to load system classes.
1196  *
1197  */
1198 
1199 typedef int (*canonicalize_fn_t)(JNIEnv *env, char *orig, char *out, int len);
1200 
1201 /*************************************************************************
1202  PART 3: I/O and Network Support
1203  ************************************************************************/
1204 
1205 /* Note that the JVM IO functions are expected to return JVM_IO_ERR
1206  * when there is any kind of error. The caller can then use the
1207  * platform specific support (e.g., errno) to get the detailed
1208  * error info.  The JVM_GetLastErrorString procedure may also be used
1209  * to obtain a descriptive error string.
1210  */
1211 #define JVM_IO_ERR  (-1)
1212 
1213 /* For interruptible IO. Returning JVM_IO_INTR indicates that an IO
1214  * operation has been disrupted by Thread.interrupt. There are a
1215  * number of technical difficulties related to interruptible IO that
1216  * need to be solved. For example, most existing programs do not handle
1217  * InterruptedIOExceptions specially, they simply treat those as any
1218  * IOExceptions, which typically indicate fatal errors.
1219  *
1220  * There are also two modes of operation for interruptible IO. In the
1221  * resumption mode, an interrupted IO operation is guaranteed not to
1222  * have any side-effects, and can be restarted. In the termination mode,
1223  * an interrupted IO operation corrupts the underlying IO stream, so
1224  * that the only reasonable operation on an interrupted stream is to
1225  * close that stream. The resumption mode seems to be impossible to
1226  * implement on Win32 and Solaris. Implementing the termination mode is
1227  * easier, but it's not clear that's the right semantics.
1228  *
1229  * Interruptible IO is not supported on Win32.It can be enabled/disabled
1230  * using a compile-time flag on Solaris. Third-party JVM ports do not
1231  * need to implement interruptible IO.
1232  */
1233 #define JVM_IO_INTR (-2)
1234 
1235 /* Write a string into the given buffer, in the platform's local encoding,
1236  * that describes the most recent system-level error to occur in this thread.
1237  * Return the length of the string or zero if no error occurred.
1238  */
1239 JNIEXPORT jint JNICALL
1240 JVM_GetLastErrorString(char *buf, int len);
1241 
1242 /*
1243  * Convert a pathname into native format.  This function does syntactic
1244  * cleanup, such as removing redundant separator characters.  It modifies
1245  * the given pathname string in place.
1246  */
1247 JNIEXPORT char * JNICALL
1248 JVM_NativePath(char *);
1249 
1250 /*
1251  * JVM I/O error codes
1252  */
1253 #define JVM_EEXIST       -100
1254 
1255 /*
1256  * Open a file descriptor. This function returns a negative error code
1257  * on error, and a non-negative integer that is the file descriptor on
1258  * success.
1259  */
1260 JNIEXPORT jint JNICALL
1261 JVM_Open(const char *fname, jint flags, jint mode);
1262 
1263 /*
1264  * Close a file descriptor. This function returns -1 on error, and 0
1265  * on success.
1266  *
1267  * fd        the file descriptor to close.
1268  */
1269 JNIEXPORT jint JNICALL
1270 JVM_Close(jint fd);
1271 
1272 /*
1273  * Read data from a file decriptor into a char array.
1274  *
1275  * fd        the file descriptor to read from.
1276  * buf       the buffer where to put the read data.
1277  * nbytes    the number of bytes to read.
1278  *
1279  * This function returns -1 on error, and 0 on success.
1280  */
1281 JNIEXPORT jint JNICALL
1282 JVM_Read(jint fd, char *buf, jint nbytes);
1283 
1284 /*
1285  * Write data from a char array to a file decriptor.
1286  *
1287  * fd        the file descriptor to read from.
1288  * buf       the buffer from which to fetch the data.
1289  * nbytes    the number of bytes to write.
1290  *
1291  * This function returns -1 on error, and 0 on success.
1292  */
1293 JNIEXPORT jint JNICALL
1294 JVM_Write(jint fd, char *buf, jint nbytes);
1295 
1296 /*
1297  * Returns the number of bytes available for reading from a given file
1298  * descriptor
1299  */
1300 JNIEXPORT jint JNICALL
1301 JVM_Available(jint fd, jlong *pbytes);
1302 
1303 /*
1304  * Move the file descriptor pointer from whence by offset.
1305  *
1306  * fd        the file descriptor to move.
1307  * offset    the number of bytes to move it by.
1308  * whence    the start from where to move it.
1309  *
1310  * This function returns the resulting pointer location.
1311  */
1312 JNIEXPORT jlong JNICALL
1313 JVM_Lseek(jint fd, jlong offset, jint whence);
1314 
1315 /*
1316  * Set the length of the file associated with the given descriptor to the given
1317  * length.  If the new length is longer than the current length then the file
1318  * is extended; the contents of the extended portion are not defined.  The
1319  * value of the file pointer is undefined after this procedure returns.
1320  */
1321 JNIEXPORT jint JNICALL
1322 JVM_SetLength(jint fd, jlong length);
1323 
1324 /*
1325  * Synchronize the file descriptor's in memory state with that of the
1326  * physical device.  Return of -1 is an error, 0 is OK.
1327  */
1328 JNIEXPORT jint JNICALL
1329 JVM_Sync(jint fd);
1330 
1331 /*
1332  * Networking library support
1333  */
1334 
1335 JNIEXPORT jint JNICALL
1336 JVM_InitializeSocketLibrary(void);
1337 
1338 struct sockaddr;
1339 
1340 JNIEXPORT jint JNICALL
1341 JVM_Socket(jint domain, jint type, jint protocol);
1342 
1343 JNIEXPORT jint JNICALL
1344 JVM_SocketClose(jint fd);
1345 
1346 JNIEXPORT jint JNICALL
1347 JVM_SocketShutdown(jint fd, jint howto);
1348 
1349 JNIEXPORT jint JNICALL
1350 JVM_Recv(jint fd, char *buf, jint nBytes, jint flags);
1351 
1352 JNIEXPORT jint JNICALL
1353 JVM_Send(jint fd, char *buf, jint nBytes, jint flags);
1354 
1355 JNIEXPORT jint JNICALL
1356 JVM_Timeout(int fd, long timeout);
1357 
1358 JNIEXPORT jint JNICALL
1359 JVM_Listen(jint fd, jint count);
1360 
1361 JNIEXPORT jint JNICALL
1362 JVM_Connect(jint fd, struct sockaddr *him, jint len);
1363 
1364 JNIEXPORT jint JNICALL
1365 JVM_Bind(jint fd, struct sockaddr *him, jint len);
1366 
1367 JNIEXPORT jint JNICALL
1368 JVM_Accept(jint fd, struct sockaddr *him, jint *len);
1369 
1370 JNIEXPORT jint JNICALL
1371 JVM_RecvFrom(jint fd, char *buf, int nBytes,
1372                   int flags, struct sockaddr *from, int *fromlen);
1373 
1374 JNIEXPORT jint JNICALL
1375 JVM_SendTo(jint fd, char *buf, int len,
1376                 int flags, struct sockaddr *to, int tolen);
1377 
1378 JNIEXPORT jint JNICALL
1379 JVM_SocketAvailable(jint fd, jint *result);
1380 
1381 
1382 JNIEXPORT jint JNICALL
1383 JVM_GetSockName(jint fd, struct sockaddr *him, int *len);
1384 
1385 JNIEXPORT jint JNICALL
1386 JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen);
1387 
1388 JNIEXPORT jint JNICALL
1389 JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen);
1390 
1391 /*
1392  * These routines are only reentrant on Windows
1393  */
1394 
1395 #ifdef _WINDOWS
1396 
1397 JNIEXPORT struct protoent * JNICALL
1398 JVM_GetProtoByName(char* name);
1399 
1400 JNIEXPORT struct hostent* JNICALL
1401 JVM_GetHostByAddr(const char* name, int len, int type);
1402 
1403 JNIEXPORT struct hostent* JNICALL
1404 JVM_GetHostByName(char* name);
1405 
1406 #endif /* _WINDOWS */
1407 
1408 JNIEXPORT int JNICALL
1409 JVM_GetHostName(char* name, int namelen);
1410 
1411 /*
1412  * The standard printing functions supported by the Java VM. (Should they
1413  * be renamed to JVM_* in the future?
1414  */
1415 
1416 /*
1417  * BE CAREFUL! The following functions do not implement the
1418  * full feature set of standard C printf formats.
1419  */
1420 int
1421 jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
1422 
1423 int
1424 jio_snprintf(char *str, size_t count, const char *fmt, ...);
1425 
1426 int
1427 jio_fprintf(FILE *, const char *fmt, ...);
1428 
1429 int
1430 jio_vfprintf(FILE *, const char *fmt, va_list args);
1431 
1432 
1433 JNIEXPORT void * JNICALL
1434 JVM_RawMonitorCreate(void);
1435 
1436 JNIEXPORT void JNICALL
1437 JVM_RawMonitorDestroy(void *mon);
1438 
1439 JNIEXPORT jint JNICALL
1440 JVM_RawMonitorEnter(void *mon);
1441 
1442 JNIEXPORT void JNICALL
1443 JVM_RawMonitorExit(void *mon);
1444 
1445 
1446 #ifdef SUPPORT_OLD_REFLECTION
1447 
1448 /*
1449  * Support for old native code-based (pre-JDK 1.4) reflection implementation.
1450  * Disabled by default in the product build.
1451  *
1452  * See reflection.hpp for information on SUPPORT_OLD_REFLECTION
1453  */
1454 
1455 /*
1456  * reflecting fields and methods.
1457  * which: 0 --- MEMBER_PUBLIC
1458  *        1 --- MEMBER_DECLARED
1459  * NOTE: absent in product build by default
1460  */
1461 
1462 JNIEXPORT jobjectArray JNICALL
1463 JVM_GetClassFields(JNIEnv *env, jclass cls, jint which);
1464 
1465 JNIEXPORT jobjectArray JNICALL
1466 JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which);
1467 
1468 JNIEXPORT jobjectArray JNICALL
1469 JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which);
1470 
1471 JNIEXPORT jobject JNICALL
1472 JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which);
1473 
1474 JNIEXPORT jobject JNICALL
1475 JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types,
1476                    jint which);
1477 JNIEXPORT jobject JNICALL
1478 JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types,
1479                         jint which);
1480 
1481 /*
1482  * Implements Class.newInstance
1483  */
1484 JNIEXPORT jobject JNICALL
1485 JVM_NewInstance(JNIEnv *env, jclass cls);
1486 
1487 /*
1488  * java.lang.reflect.Field
1489  */
1490 JNIEXPORT jobject JNICALL
1491 JVM_GetField(JNIEnv *env, jobject field, jobject obj);
1492 
1493 JNIEXPORT jvalue JNICALL
1494 JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj,
1495                       unsigned char wCode);
1496 
1497 JNIEXPORT void JNICALL
1498 JVM_SetField(JNIEnv *env, jobject field, jobject obj, jobject val);
1499 
1500 JNIEXPORT void JNICALL
1501 JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v,
1502                       unsigned char vCode);
1503 
1504 /*
1505  * java.lang.reflect.Method
1506  */
1507 JNIEXPORT jobject JNICALL
1508 JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0);
1509 
1510 /*
1511  * java.lang.reflect.Constructor
1512  */
1513 JNIEXPORT jobject JNICALL
1514 JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0);
1515 
1516 #endif /* SUPPORT_OLD_REFLECTION */
1517 
1518 /*
1519  * java.lang.management support
1520  */
1521 JNIEXPORT void* JNICALL
1522 JVM_GetManagement(jint version);
1523 
1524 /*
1525  * com.sun.tools.attach.VirtualMachine support
1526  *
1527  * Initialize the agent properties with the properties maintained in the VM.
1528  */
1529 JNIEXPORT jobject JNICALL
1530 JVM_InitAgentProperties(JNIEnv *env, jobject agent_props);
1531 
1532 /* Generics reflection support.
1533  *
1534  * Returns information about the given class's EnclosingMethod
1535  * attribute, if present, or null if the class had no enclosing
1536  * method.
1537  *
1538  * If non-null, the returned array contains three elements. Element 0
1539  * is the java.lang.Class of which the enclosing method is a member,
1540  * and elements 1 and 2 are the java.lang.Strings for the enclosing
1541  * method's name and descriptor, respectively.
1542  */
1543 JNIEXPORT jobjectArray JNICALL
1544 JVM_GetEnclosingMethodInfo(JNIEnv* env, jclass ofClass);
1545 
1546 /*
1547  * Java thread state support
1548  */
1549 enum {
1550     JAVA_THREAD_STATE_NEW           = 0,
1551     JAVA_THREAD_STATE_RUNNABLE      = 1,
1552     JAVA_THREAD_STATE_BLOCKED       = 2,
1553     JAVA_THREAD_STATE_WAITING       = 3,
1554     JAVA_THREAD_STATE_TIMED_WAITING = 4,
1555     JAVA_THREAD_STATE_TERMINATED    = 5,
1556     JAVA_THREAD_STATE_COUNT         = 6
1557 };
1558 
1559 /*
1560  * Returns an array of the threadStatus values representing the
1561  * given Java thread state.  Returns NULL if the VM version is
1562  * incompatible with the JDK or doesn't support the given
1563  * Java thread state.
1564  */
1565 JNIEXPORT jintArray JNICALL
1566 JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState);
1567 
1568 /*
1569  * Returns an array of the substate names representing the
1570  * given Java thread state.  Returns NULL if the VM version is
1571  * incompatible with the JDK or the VM doesn't support
1572  * the given Java thread state.
1573  * values must be the jintArray returned from JVM_GetThreadStateValues
1574  * and javaThreadState.
1575  */
1576 JNIEXPORT jobjectArray JNICALL
1577 JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values);
1578 
1579 /* =========================================================================
1580  * The following defines a private JVM interface that the JDK can query
1581  * for the JVM version and capabilities.  sun.misc.Version defines
1582  * the methods for getting the VM version and its capabilities.
1583  *
1584  * When a new bit is added, the following should be updated to provide
1585  * access to the new capability:
1586  *    HS:   JVM_GetVersionInfo and Abstract_VM_Version class
1587  *    SDK:  Version class
1588  *
1589  * Similary, a private JDK interface JDK_GetVersionInfo0 is defined for
1590  * JVM to query for the JDK version and capabilities.
1591  *
1592  * When a new bit is added, the following should be updated to provide
1593  * access to the new capability:
1594  *    HS:   JDK_Version class
1595  *    SDK:  JDK_GetVersionInfo0
1596  *
1597  * ==========================================================================
1598  */
1599 typedef struct {
1600     /* HotSpot Express VM version string:
1601      * <major>.<minor>-bxx[-<identifier>][-<debug_flavor>]
1602      */
1603     unsigned int jvm_version; /* Consists of major.minor.0.build */
1604     unsigned int update_version : 8;         /* 0 in HotSpot Express VM */
1605     unsigned int special_update_version : 8; /* 0 in HotSpot Express VM */
1606     unsigned int reserved1 : 16;
1607     unsigned int reserved2;
1608 
1609     /* The following bits represents JVM supports that JDK has dependency on.
1610      * JDK can use these bits to determine which JVM version
1611      * and support it has to maintain runtime compatibility.
1612      *
1613      * When a new bit is added in a minor or update release, make sure
1614      * the new bit is also added in the main/baseline.
1615      */
1616     unsigned int is_attachable : 1;
1617     unsigned int is_kernel_jvm : 1;
1618     unsigned int : 30;
1619     unsigned int : 32;
1620     unsigned int : 32;
1621 } jvm_version_info;
1622 
1623 #define JVM_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24)
1624 #define JVM_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16)
1625 // Micro version is 0 in HotSpot Express VM (set in jvm.cpp).
1626 #define JVM_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8)
1627 /* Build number is available in all HotSpot Express VM builds.
1628  * It is defined in make/hotspot_version file.
1629  */
1630 #define JVM_VERSION_BUILD(version) ((version & 0x000000FF))
1631 
1632 JNIEXPORT void JNICALL
1633 JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size);
1634 
1635 typedef struct {
1636     // Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx
1637     unsigned int jdk_version;   /* Consists of major, minor, micro (n.n.n) */
1638                                 /* and build number (xx) */
1639     unsigned int update_version : 8;         /* Update release version (uu) */
1640     unsigned int special_update_version : 8; /* Special update release version (c)*/
1641     unsigned int reserved1 : 16;
1642     unsigned int reserved2;
1643 
1644     /* The following bits represents new JDK supports that VM has dependency on.
1645      * VM implementation can use these bits to determine which JDK version
1646      * and support it has to maintain runtime compatibility.
1647      *
1648      * When a new bit is added in a minor or update release, make sure
1649      * the new bit is also added in the main/baseline.
1650      */
1651     unsigned int thread_park_blocker : 1;
1652     unsigned int : 31;
1653     unsigned int : 32;
1654     unsigned int : 32;
1655 } jdk_version_info;
1656 
1657 #define JDK_VERSION_MAJOR(version) ((version & 0xFF000000) >> 24)
1658 #define JDK_VERSION_MINOR(version) ((version & 0x00FF0000) >> 16)
1659 #define JDK_VERSION_MICRO(version) ((version & 0x0000FF00) >> 8)
1660 
1661 /* Build number is available only for RE build (i.e. JDK_BUILD_NUMBER is set to bNN)
1662  * It will be zero for internal builds.
1663  */
1664 #define JDK_VERSION_BUILD(version) ((version & 0x000000FF))
1665 
1666 /*
1667  * This is the function JDK_GetVersionInfo0 defined in libjava.so
1668  * that is dynamically looked up by JVM.
1669  */
1670 typedef void (*jdk_version_info_fn_t)(jdk_version_info* info, size_t info_size);
1671 
1672 /*
1673  * This structure is used by the launcher to get the default thread
1674  * stack size from the VM using JNI_GetDefaultJavaVMInitArgs() with a
1675  * version of 1.1.  As it is not supported otherwise, it has been removed
1676  * from jni.h
1677  */
1678 typedef struct JDK1_1InitArgs {
1679     jint version;
1680 
1681     char **properties;
1682     jint checkSource;
1683     jint nativeStackSize;
1684     jint javaStackSize;
1685     jint minHeapSize;
1686     jint maxHeapSize;
1687     jint verifyMode;
1688     char *classpath;
1689 
1690     jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args);
1691     void (JNICALL *exit)(jint code);
1692     void (JNICALL *abort)(void);
1693 
1694     jint enableClassGC;
1695     jint enableVerboseGC;
1696     jint disableAsyncGC;
1697     jint verbose;
1698     jboolean debugging;
1699     jint debugPort;
1700 } JDK1_1InitArgs;
1701 
1702 #ifdef __cplusplus
1703 } /* extern "C" */
1704 #endif /* __cplusplus */
1705 
1706 #endif /* !_JAVASOFT_JVM_H_ */