Package org.apache.kato.katoview.commands.infocommands

Source Code of org.apache.kato.katoview.commands.infocommands.InfoJitmCommand

/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.apache.kato.katoview.commands.infocommands;

import java.util.HashMap;
import java.util.Stack;
import java.util.Iterator;

import javax.tools.diagnostics.image.CorruptDataException;
import javax.tools.diagnostics.image.Image;
import javax.tools.diagnostics.image.ImageSection;
import javax.tools.diagnostics.runtime.java.JavaClass;
import javax.tools.diagnostics.runtime.java.JavaClassLoader;
import javax.tools.diagnostics.runtime.java.JavaMethod;
import javax.tools.diagnostics.runtime.java.JavaRuntime;

import org.apache.kato.katoview.Output;
import org.apache.kato.katoview.commands.Command;
import org.apache.kato.katoview.commands.helpers.Exceptions;
import org.apache.kato.katoview.commands.helpers.Utils;


public class InfoJitmCommand extends Command {

  public InfoJitmCommand(Output o){
    super(o, "jitm", "displays JIT'ed methods and their addresses",
        "parameters: none\n\n" +
        "prints the following information about each JIT'ed method\n\n" +
        "  - method name and signature\n" +
        "  - method start address\n" +
        "  - method end address\n"
    );
    child_commands = null;
  }
 
  public void doCommand(Stack args, Image loadedImage, HashMap properties){
    if (!args.isEmpty())
    {
      out.error("\"info jitm\" command does not take any parameters");
    }
    else
    {
      Iterator itJavaRuntime = Utils.getRuntimes(loadedImage);
      while (itJavaRuntime.hasNext())
      {
        JavaRuntime jr = (JavaRuntime)itJavaRuntime.next();
        Iterator itJavaClassLoader = jr.getJavaClassLoaders().iterator();
        while (itJavaClassLoader.hasNext())
        {
          JavaClassLoader jcl = (JavaClassLoader)itJavaClassLoader.next();
          Iterator itJavaClass = jcl.getDefinedClasses().iterator();
         
          while (itJavaClass.hasNext())
          {
            JavaClass jc = (JavaClass)itJavaClass.next();
            Iterator itJavaMethod = jc.getDeclaredMethods().iterator();
           
            String jcName;
            try {
              jcName = jc.getName();
            } catch (CorruptDataException e) {
              jcName = Exceptions.getCorruptDataExceptionString();
            }
           
            while (itJavaMethod.hasNext())
            {
              JavaMethod jm = (JavaMethod)itJavaMethod.next();
              String name;
              String sig;
             
              try {
                name = jm.getName();
              } catch (CorruptDataException e) {
                name = Exceptions.getCorruptDataExceptionString();
              }
             
              try {
                sig = jm.getSignature();
              } catch (CorruptDataException e) {
                sig = Exceptions.getCorruptDataExceptionString();
              }

              if (jm.getCompiledSections().isEmpty()==false)
              {
                Iterator itImageSection = jm.getCompiledSections().iterator();
                while (itImageSection.hasNext())
                {
                  ImageSection is = (ImageSection)itImageSection.next();
                  long startAddr = is.getBaseAddress().getAddress();
                  long size = is.getSize();
                  long endAddr = startAddr + size;
                 
                  out.print("\n\t" + "start=" + Utils.toHex(startAddr) +
                      "  " + "end=" + Utils.toHex(endAddr) +
                      "   " + jcName + "::" + name + sig);
                }
              }
            }
          }
        }
      }
    }
    out.print("\n");
  }
}
TOP

Related Classes of org.apache.kato.katoview.commands.infocommands.InfoJitmCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.