openjdk17 hotspot new对象内部字段在jhsdb展示

##openjdk17 hotspot java new对象在C++源码实现逻辑

类名字,java对象地址

std::cout << "@@@@yym%%%%obj address " << klass->name()->as_C_string() << obj << "----begin" << std::endl;

JRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* current, ConstantPool* pool, int index))
  Klass* k = pool->klass_at(index, CHECK);
  InstanceKlass* klass = InstanceKlass::cast(k);

  // Make sure we are not instantiating an abstract klass
  klass->check_valid_for_instantiation(true, CHECK);

  // Make sure klass is initialized
  klass->initialize(CHECK);

  // At this point the class may not be fully initialized
  // because of recursive initialization. If it is fully
  // initialized & has_finalized is not set, we rewrite
  // it into its fast version (Note: no locking is needed
  // here since this is an atomic byte write and can be
  // done more than once).
  //
  // Note: In case of classes with has_finalized we don't
  //       rewrite since that saves us an extra check in
  //       the fast version which then would call the
  //       slow version anyway (and do a call back into
  //       Java).
  //       If we have a breakpoint, then we don't rewrite
  //       because the _breakpoint bytecode would be lost.
  oop obj = klass->allocate_instance(CHECK);
  std::cout << "@@@@yym%%%%obj address " << klass->name()->as_C_string() << obj << "----begin" << std::endl;
  current->set_vm_result(obj);
JRT_END

##打印对象地址

##在jhsdb查看

##java 测试类

public class ByteCodeTest {

    private int insert=678;

    public static void main(String[] args) throws Exception {
        ByteCodeTest byteCodeTest = new ByteCodeTest();
        Method method = ByteCodeTest.class.getDeclaredMethod("testYYM", int.class, int.class);
        Object result = method.invoke(byteCodeTest, 1,2);
        System.out.println(result);
        System.in.read();
    }

    public int testYYM(int a, int b) {
        int c = 0;
        while(a>b) {
            c = a-b;
        }
        c=c+1+this.insert;
        return c;
    }

}

上一篇:《等保测评:企业信息安全的全面升级》


下一篇:ubuntn22.04安装iredmail