`
caoxudong818
  • 浏览: 44032 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Serviceability 简介 —— 概述

 
阅读更多

以下内容均已jdk1.7.0_04为准。

 

啥是 Serviceability ?

 

HotSpot Glossary of Terms 写道
Serviceability Agent (SA)
The Serviceablity Agent is collection of Sun internal code that aids in debugging HotSpot problems. It is also used by several JDK tools - jstack, jmap, jinfo, and jdb. See SA for more information.

 简单说,这部分是用来调试查看hotspot的。

 

子曰,学而时习之 不亦说乎。这里就先习之,有个直观印象之后,再学之。

平时用来查看hotspot内部信息的常用的工具都在$JAVA_HOME/bin目录下,其中一些工具就是用Serviceability开发的。这里要介绍的是HSDB(其命令版本是CLHSDB),启动方式如下:

 

java -classpath $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.HSDB

 

看到界面后,大家自己琢磨怎么玩吧,内容挺多。

 

类似的,启动CLHSDB的方式如下: 

 

java -classpath $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB

 

 这里有一个简单的说明文档:http://hg.openjdk.java.net/hsx/hotspot-main/hotspot/raw-file/tip/agent/doc/clhsdb.html

 

另外,还有一个DebugServer类,功能差不多。

 

java -classpath %JAVA_HOME%/lib/sa-jdi.jar sun.jvm.hotspot.DebugServer

 

在sun.jvm.hotspot包下,有个HelloWorld类。我觉着此类是在蛋疼的紧,各位请看代码:

 

/*
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

package sun.jvm.hotspot;

import java.lang.reflect.*;

public class HelloWorld {
  private static String helloWorldString = "Hello, world!";
  private static volatile int helloWorldTrigger = 0;
  private static final boolean useMethodInvoke = false;
  private static Object lock = new Object();

  public static void main(String[] args) {
    int foo = a();

    System.out.println("HelloWorld exiting. a() = " + foo);
  }

  private static int a() {
    return 1 + b();
  }

  private static int b() {
    return 1 + c();
  }

  private static int c() {
    return 1 + d("Hi");
  }

  private static int d(String x) {
    System.out.println("HelloWorld.d() received \"" + x + "\" as argument");
    synchronized(lock) {
      if (useMethodInvoke) {
        try {
          Method method = HelloWorld.class.getMethod("e");
          Integer result = (Integer) method.invoke(null, new Object[0]);
          return result.intValue();
        }
        catch (Exception e) {
          throw new RuntimeException(e.toString());
        }
      } else {

        int i = fib(10); // 89
        long l = i;
        float f = i;
        double d = i;
        char c = (char) i;
        short s = (short) i;
        byte b = (byte) i;

        int ret = e();

        System.out.println("Tenth Fibonacci number in all formats: " +
                           i + ", " +
                           l + ", " +
                           f + ", " +
                           d + ", " +
                           c + ", " +
                           s + ", " +
                           b);

        return ret;
      }
    }
  }

  public static int e() {
    System.out.println("Going to sleep...");

    int i = 0;

    while (helloWorldTrigger == 0) {
      if (++i == 1000000) {
        System.gc();
      }
    }

    System.out.println(helloWorldString);

    while (helloWorldTrigger != 0) {
    }

    return i;
  }

  // Tree-recursive implementation for test
  public static int fib(int n) {
    if (n < 2) {
      return 1;
    }
    return fib(n - 1) + fib(n - 2);
  }
}

 难道此类是用来硬件测性能的?

 

sa中的包主要分为以下几个部分:

asm,ci,code,debugger,gc,interpreter,jdi,livevm,memory,oops,opto,prims,runtine,tools,types。

后续的文章会进行介绍,可能会跳过一些(我不懂的)。

 

回到CLHSDB,这个只是一个壳,主要的功能都是靠sun.jvm.hotspot.HotSpotAgent和sun.jvm.hotspot.CommandProcessor完成的。

 

CommandProcessor.DebuggerInterface di = new CommandProcessor.DebuggerInterface() {
                public HotSpotAgent getAgent() {
                    return agent;
                }
                public boolean isAttached() {
                    return attached;
                }
                public void attach(String pid) {
                    attachDebugger(pid);
                }
                public void attach(String java, String core) {
                    attachDebugger(java, core);
                }
                public void detach() {
                    detachDebugger();
                }
                public void reattach() {
                    if (attached) {
                        detachDebugger();
                    }
                    if (pidText != null) {
                        attach(pidText);
                    } else {
                        attach(execPath, coreFilename);
                    }
                }
            };
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
CommandProcessor cp = new CommandProcessor(di, in, System.out, System.err);

构造CommandProcessor类的实例前时,会对其中的一个成员变量commandList进行初始化,其中存储的就是预先注册的可执行命令:

 

private final Command[] commandList = {
        new Command("reattach", true) {
            public void doit(Tokens t) {
                int tokens = t.countTokens();
                if (tokens != 0) {
                    usage();
                    return;
                }
                preAttach();
                debugger.reattach();
                postAttach();
            }
        },
        new Command("attach", "attach pid | exec core", true) {
            public void doit(Tokens t) {
                int tokens = t.countTokens();
                if (tokens == 1) {
                    preAttach();
                    debugger.attach(t.nextToken());
                    postAttach();
                } else if (tokens == 2) {
                    preAttach();
                    debugger.attach(t.nextToken(), t.nextToken());
                    postAttach();
                } else {
                    usage();
                }
            }
        },
......
        new Command("assert", "assert true | false", true) {
            public void doit(Tokens t) {
                if (t.countTokens() != 1) {
                    usage();
                } else {
                    Assert.ASSERTS_ENABLED = Boolean.valueOf(t.nextToken()).booleanValue();
                }
            }
        },
    };

 

这样,程序就可以接收并处理用户输入的命令。

 

HotSpotAgent类的主要功能是根据主机环境设置调试器(debugger),并将debugger attach(这词儿该咋表述)到目标上(目标可以通过PID或dump文件)。流程如下(以Windows为例):

attach($pid) -> setupDebugger() -> setupDebuggerWin32() -> attachDebugger()

在这期间会根据需要,判断是否建立一个远程调式服务器,以便于执行远程调试。

 

if (isServer) {
    RemoteDebuggerServer remote = null;
    try {
        remote = new RemoteDebuggerServer(debugger);
    }catch (RemoteException rem) {
        throw new DebuggerException(rem);
    }
    RMIHelper.rebind(serverID, remote);
}
 

 

to be continued...

分享到:
评论
1 楼 qiuboboy 2013-04-09  

相关推荐

    鸿蒙关于js与serviceAbility交互的Demo讲解

    鸿蒙系统

    Reliability, Availability and Serviceability on Linux.pdf

    Reliability, Availability and Serviceability on Linux.pdf

    服务器系统概述(全文).doc

    它负责将电脑的核心——微处 理器和机器的其他部分相连接,是决定主板级别的重要部件。以往,芯片组由多颗芯片 组成,慢慢的简化为两颗芯片。在计算机领域,"芯片组"术语通常是特指计算机主板或 扩展卡上的芯片。 在...

    Service实现通知,判断通知栏是否已打开

    Service实现通知,判断通知栏是否已打开

    Java.Performance.Companion.0133796825

    Using HotSpot VM Serviceability Agent to analyze, triage, and resolve diverse HotSpot VM issues Troubleshooting out of memory errors, Java level deadlocks, and HotSpot VM crashes Extending the ...

    Java Performance Companion(Addison,2016)

    Using HotSpot VM Serviceability Agent to analyze, triage, and resolve diverse HotSpot VM issues Troubleshooting out of memory errors, Java level deadlocks, and HotSpot VM crashes Extending the ...

    DDI0587D_b_RAS_Supplement.pdf

    Reliability, Availability, and Serviceability (RAS), for Armv8-A

    BSEN1993-1-12-2007Eurocode3—designofsteelstructures

    It complies with the principles and requirements for the safety and serviceability of structures, the basis of their design and verification that are given in EN 1990 – Basis of structural design....

    linux集群 heartbeat应用

    Linux-HA的全称是High-Availability Linux,这个开源项目的目标是:通过社区开发者的共同努力,提供一个增强linux可靠性(reliability)、可用性(availability)和可服务性(serviceability)(RAS)的群集解决方案...

    ArmARM v8-A Supplement - RAS

    ARM® Reliability, Availability, and Serviceability (RAS) Specification ARMv8, for the ARMv8-A architecture profile

    华为E9000 服务器 V100R001

    Availability, and Serviceability)、计算密度、节能减排、背板带宽、智能管控与服务、 计算与存储的弹性配置和灵活扩展、网络低时延和加速方面具有领先的竞争力: l 提供与小型机相当的品质和服务能力,为电信运营...

    蓝牙音箱.rar

    概述GENERAL 1.1 适用范围 APPLICATION 此规格书适用于机械式轻触开关的相关要求 This specification is applied to the requirements for TACTILE SWITCH (MECHANICAL CONTACT) 1.2 工作温度范围 Operating ...

    Structural Health Monitoring of Long-Span Suspension Bridges

    In recent decades, structural health monitoring systems have been developed to measure the loading environment and responses of these bridges in order to assess serviceability and safety while ...

    visualVm1.4.2分析工具.rar

    VisualVM 是一款免费的性能分析工具。它通过 jvmstat、JMX、SA(Serviceability Agent)以及 Attach API 等多种方式从程序运行时获得实时数据,从而进行动态的性能分析。

    PICMG3.0 R3.0 AdvancedTCA Base Specification

    Provide high levels of service availability (99.999% and greater) through the integration of features for resiliency, redundancy, serviceability and manageability Support appropriate scalability of ...

    服务器与小型机的比较.docx

    小型机与PC服务器的简单比较 小型机的最主要的三个优势(Reliability, Availability, Serviceability 高可靠性、高可用性、高服务性) 小型机 1,小型机是封闭专用的计算机系统,CPU一般采用RISC技术即简单指令集...

    VisualVM1_3_9多语言版本(visualvm_139-ml.zip)及离线插件包(plugins for 1.3.9.rar)

    VisualVM1.3.9(2017年11月从官网下载并安装插件验证通过)通过 jvmstat、JMX、SA(Serviceability Agent)以及 Attach API 等多种方式从程序运行时获得实时数据,从而进行动态的性能分析。同时,它能自动选择更快更...

    VisualVM_139 for mac

    它通过 jvmstat、JMX、SA(Serviceability Agent)以及 Attach API 等多种方式从程序运行时获得实时数据,从而进行动态的性能分析。同时,它能自动选择更快更轻量级的技术尽量减少性能分析对应用程序造成的影响,...

    工业电子中的图解CompactPCI的优点

     CompactPCI本身所具有的高可热插拔、抗震性强、高可用性(Availability)、易使用性(Serviceability)、可扩展性(Scalability)等特性完全适合工业级的应用。所以采用CompactPCI架构的工业PC,相对商业PC的架构...

    图解CompactPCI的优点

     CompactPCI本身所具有的高可热插拔、抗震性强、高可用性(Availability)、易使用性(Serviceability)、可扩展性(Scalability)等特性完全适合工业级的应用。所以采用CompactPCI架构的工业PC,相对商业PC的架构...

Global site tag (gtag.js) - Google Analytics