< prev index next >

src/hotspot/share/ci/ciEnv.cpp

Print this page

   1 /*
   2  * Copyright (c) 1999, 2025, 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  *

  46 #include "compiler/compilerEvent.hpp"
  47 #include "compiler/compileTask.hpp"
  48 #include "compiler/disassembler.hpp"
  49 #include "gc/shared/collectedHeap.inline.hpp"
  50 #include "interpreter/bytecodeStream.hpp"
  51 #include "interpreter/linkResolver.hpp"
  52 #include "jfr/jfrEvents.hpp"
  53 #include "jvm.h"
  54 #include "logging/log.hpp"
  55 #include "memory/allocation.inline.hpp"
  56 #include "memory/oopFactory.hpp"
  57 #include "memory/resourceArea.hpp"
  58 #include "memory/universe.hpp"
  59 #include "oops/constantPool.inline.hpp"
  60 #include "oops/cpCache.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/methodData.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"

  66 #include "oops/resolvedIndyEntry.hpp"
  67 #include "oops/symbolHandle.hpp"
  68 #include "prims/jvmtiExport.hpp"
  69 #include "prims/methodHandles.hpp"
  70 #include "runtime/fieldDescriptor.inline.hpp"
  71 #include "runtime/handles.inline.hpp"
  72 #include "runtime/init.hpp"
  73 #include "runtime/javaThread.hpp"
  74 #include "runtime/jniHandles.inline.hpp"
  75 #include "runtime/reflection.hpp"
  76 #include "runtime/safepointVerifiers.hpp"
  77 #include "runtime/sharedRuntime.hpp"
  78 #include "utilities/dtrace.hpp"
  79 #include "utilities/macros.hpp"
  80 #ifdef COMPILER1
  81 #include "c1/c1_Runtime1.hpp"
  82 #endif
  83 #ifdef COMPILER2
  84 #include "opto/runtime.hpp"
  85 #endif

 472   // If we fail to find an array klass, look again for its element type.
 473   // The element type may be available either locally or via constraints.
 474   // In either case, if we can find the element type in the system dictionary,
 475   // we must build an array type around it.  The CI requires array klasses
 476   // to be loaded if their element klasses are loaded, except when memory
 477   // is exhausted.
 478   if (Signature::is_array(sym) &&
 479       (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
 480     // We have an unloaded array.
 481     // Build it on the fly if the element class exists.
 482     SignatureStream ss(sym, false);
 483     ss.skip_array_prefix(1);
 484     // Get element ciKlass recursively.
 485     ciKlass* elem_klass =
 486       get_klass_by_name_impl(accessing_klass,
 487                              cpool,
 488                              get_symbol(ss.as_symbol()),
 489                              require_local);
 490     if (elem_klass != nullptr && elem_klass->is_loaded()) {
 491       // Now make an array for it
 492       return ciObjArrayKlass::make_impl(elem_klass);
 493     }
 494   }
 495 
 496   if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
 497     // Look inside the constant pool for pre-resolved class entries.
 498     for (int i = cpool->length() - 1; i >= 1; i--) {
 499       if (cpool->tag_at(i).is_klass()) {
 500         Klass* kls = cpool->resolved_klass_at(i);
 501         if (kls->name() == sym) {
 502           found_klass = kls;
 503           break;
 504         }
 505       }
 506     }
 507   }
 508 
 509   if (found_klass != nullptr) {
 510     // Found it.  Build a CI handle.
 511     return get_klass(found_klass);
 512   }

1341   }
1342 }
1343 
1344 // Read an object field.  Lookup is done by name only.
1345 static inline oop obj_field(oop obj, const char* name) {
1346     return ciReplay::obj_field(obj, name);
1347 }
1348 
1349 // Process a java.lang.invoke.LambdaForm object and record any dynamic locations.
1350 void ciEnv::record_lambdaform(Thread* thread, oop form) {
1351   assert(java_lang_invoke_LambdaForm::is_instance(form), "!");
1352 
1353   {
1354     // Check LambdaForm.vmentry field
1355     oop member = java_lang_invoke_LambdaForm::vmentry(form);
1356     RecordLocation fp0(this, "vmentry");
1357     record_member(thread, member);
1358   }
1359 
1360   // Check LambdaForm.names array
1361   objArrayOop names = (objArrayOop)obj_field(form, "names");


1362   if (names != nullptr) {
1363     RecordLocation lp0(this, "names");
1364     int len = names->length();
1365     for (int i = 0; i < len; ++i) {
1366       oop name = names->obj_at(i);
1367       RecordLocation lp1(this, "%d", i);
1368      // Check LambdaForm.names[i].function field
1369       RecordLocation lp2(this, "function");
1370       oop function = obj_field(name, "function");
1371       if (function != nullptr) {
1372         // Check LambdaForm.names[i].function.member field
1373         oop member = obj_field(function, "member");
1374         if (member != nullptr) {
1375           RecordLocation lp3(this, "member");
1376           record_member(thread, member);
1377         }
1378         // Check LambdaForm.names[i].function.resolvedHandle field
1379         oop mh = obj_field(function, "resolvedHandle");
1380         if (mh != nullptr) {
1381           RecordLocation lp3(this, "resolvedHandle");

   1 /*
   2  * Copyright (c) 1999, 2026, 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  *

  46 #include "compiler/compilerEvent.hpp"
  47 #include "compiler/compileTask.hpp"
  48 #include "compiler/disassembler.hpp"
  49 #include "gc/shared/collectedHeap.inline.hpp"
  50 #include "interpreter/bytecodeStream.hpp"
  51 #include "interpreter/linkResolver.hpp"
  52 #include "jfr/jfrEvents.hpp"
  53 #include "jvm.h"
  54 #include "logging/log.hpp"
  55 #include "memory/allocation.inline.hpp"
  56 #include "memory/oopFactory.hpp"
  57 #include "memory/resourceArea.hpp"
  58 #include "memory/universe.hpp"
  59 #include "oops/constantPool.inline.hpp"
  60 #include "oops/cpCache.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/methodData.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "oops/oopCast.inline.hpp"
  67 #include "oops/resolvedIndyEntry.hpp"
  68 #include "oops/symbolHandle.hpp"
  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/methodHandles.hpp"
  71 #include "runtime/fieldDescriptor.inline.hpp"
  72 #include "runtime/handles.inline.hpp"
  73 #include "runtime/init.hpp"
  74 #include "runtime/javaThread.hpp"
  75 #include "runtime/jniHandles.inline.hpp"
  76 #include "runtime/reflection.hpp"
  77 #include "runtime/safepointVerifiers.hpp"
  78 #include "runtime/sharedRuntime.hpp"
  79 #include "utilities/dtrace.hpp"
  80 #include "utilities/macros.hpp"
  81 #ifdef COMPILER1
  82 #include "c1/c1_Runtime1.hpp"
  83 #endif
  84 #ifdef COMPILER2
  85 #include "opto/runtime.hpp"
  86 #endif

 473   // If we fail to find an array klass, look again for its element type.
 474   // The element type may be available either locally or via constraints.
 475   // In either case, if we can find the element type in the system dictionary,
 476   // we must build an array type around it.  The CI requires array klasses
 477   // to be loaded if their element klasses are loaded, except when memory
 478   // is exhausted.
 479   if (Signature::is_array(sym) &&
 480       (sym->char_at(1) == JVM_SIGNATURE_ARRAY || sym->char_at(1) == JVM_SIGNATURE_CLASS)) {
 481     // We have an unloaded array.
 482     // Build it on the fly if the element class exists.
 483     SignatureStream ss(sym, false);
 484     ss.skip_array_prefix(1);
 485     // Get element ciKlass recursively.
 486     ciKlass* elem_klass =
 487       get_klass_by_name_impl(accessing_klass,
 488                              cpool,
 489                              get_symbol(ss.as_symbol()),
 490                              require_local);
 491     if (elem_klass != nullptr && elem_klass->is_loaded()) {
 492       // Now make an array for it
 493       return ciArrayKlass::make(elem_klass);
 494     }
 495   }
 496 
 497   if (found_klass == nullptr && !cpool.is_null() && cpool->has_preresolution()) {
 498     // Look inside the constant pool for pre-resolved class entries.
 499     for (int i = cpool->length() - 1; i >= 1; i--) {
 500       if (cpool->tag_at(i).is_klass()) {
 501         Klass* kls = cpool->resolved_klass_at(i);
 502         if (kls->name() == sym) {
 503           found_klass = kls;
 504           break;
 505         }
 506       }
 507     }
 508   }
 509 
 510   if (found_klass != nullptr) {
 511     // Found it.  Build a CI handle.
 512     return get_klass(found_klass);
 513   }

1342   }
1343 }
1344 
1345 // Read an object field.  Lookup is done by name only.
1346 static inline oop obj_field(oop obj, const char* name) {
1347     return ciReplay::obj_field(obj, name);
1348 }
1349 
1350 // Process a java.lang.invoke.LambdaForm object and record any dynamic locations.
1351 void ciEnv::record_lambdaform(Thread* thread, oop form) {
1352   assert(java_lang_invoke_LambdaForm::is_instance(form), "!");
1353 
1354   {
1355     // Check LambdaForm.vmentry field
1356     oop member = java_lang_invoke_LambdaForm::vmentry(form);
1357     RecordLocation fp0(this, "vmentry");
1358     record_member(thread, member);
1359   }
1360 
1361   // Check LambdaForm.names array
1362   // The type of the array is Name[] and Name is an identity class,
1363   // so the array is always an array of references
1364   refArrayOop names = oop_cast<refArrayOop>(obj_field(form, "names"));
1365   if (names != nullptr) {
1366     RecordLocation lp0(this, "names");
1367     int len = names->length();
1368     for (int i = 0; i < len; ++i) {
1369       oop name = names->obj_at(i);
1370       RecordLocation lp1(this, "%d", i);
1371      // Check LambdaForm.names[i].function field
1372       RecordLocation lp2(this, "function");
1373       oop function = obj_field(name, "function");
1374       if (function != nullptr) {
1375         // Check LambdaForm.names[i].function.member field
1376         oop member = obj_field(function, "member");
1377         if (member != nullptr) {
1378           RecordLocation lp3(this, "member");
1379           record_member(thread, member);
1380         }
1381         // Check LambdaForm.names[i].function.resolvedHandle field
1382         oop mh = obj_field(function, "resolvedHandle");
1383         if (mh != nullptr) {
1384           RecordLocation lp3(this, "resolvedHandle");
< prev index next >