/*******************************************************************************
* 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.jvmti.process;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import javax.tools.diagnostics.image.CorruptDataException;
import javax.tools.diagnostics.image.DataUnavailable;
import javax.tools.diagnostics.image.Image;
import javax.tools.diagnostics.image.ImageAddressSpace;
import javax.tools.diagnostics.image.ImageModule;
import javax.tools.diagnostics.image.ImagePointer;
import javax.tools.diagnostics.image.ImageProcess;
import javax.tools.diagnostics.image.ImageSection;
import javax.tools.diagnostics.image.ImageThread;
import javax.tools.diagnostics.runtime.ManagedRuntime;
import org.apache.kato.jvmti.javaruntime.JavaRuntimeImpl;
import org.apache.kato.jvmti.javaruntime.model.SimpleImagePointer;
import org.apache.kato.jvmti.reader.CJVMTIBinReader;
/**
* Implements the main Image hierarchy.
* There is only one instance of Image, ImageAddressSpace and ImageProcess
* in each dump, and data may be shared between all.
*
*/
public class ImageImpl implements Image, ImageAddressSpace, ImageProcess {
private List<ManagedRuntime> runtimes = new LinkedList<ManagedRuntime>();
private List<ImageAddressSpace> spaces = new LinkedList<ImageAddressSpace>();
private List<ImageProcess> processes = new LinkedList<ImageProcess>();
private File file = null;
private CJVMTIBinReader br;
public ImageImpl(File base) throws IOException {
this.file = base;
br = new CJVMTIBinReader(file);
runtimes.add(new JavaRuntimeImpl(br.getModel(), file));
spaces.add(this);
processes.add(this);
}
/* ImageProcess methods */
@Override
public String getCommandLine() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("Command line not present in CJVMTI dump.");
}
@Override
public ImageThread getCurrentThread() throws CorruptDataException {
return null;
}
@Override
public Properties getEnvironment() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("Environment variables are not present in CJVMTI dump.");
}
@Override
public ImageModule getExecutable() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("no env");
}
@Override
public String getID() throws DataUnavailable, CorruptDataException {
throw new DataUnavailable("no env");
}
@Override
public List<ImageModule> getLibraries() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("no env");
}
/**
* Regardless of the bittedness of the JVM the agent was run on,
* the dump itself is 64 bits.
*
* @return 64
*/
@Override
public int getPointerSize() {
return 64;
}
@Override
public List<ManagedRuntime> getRuntimes() {
return runtimes;
}
/* Image methods */
@Override
public String getSignalName() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("no env");
}
@Override
public int getSignalNumber() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("no env");
}
@Override
public List<ImageThread> getThreads() {
return Collections.emptyList();
}
@Override
public ImageProcess getCurrentProcess() {
return this;
}
@Override
public List<ImageSection> getImageSections() {
return Collections.emptyList();
}
@Override
public ImagePointer getPointer(long arg0) {
return new SimpleImagePointer(arg0);
}
@Override
public List<ImageProcess> getProcesses() {
return processes;
}
@Override
public List<ImageAddressSpace> getAddressSpaces() {
return spaces;
}
@Override
public long getCreationTime() throws DataUnavailable {
return br.getCreationTime();
}
@Override
public String getHostName() throws DataUnavailable, CorruptDataException {
return "host";
}
@Override
public Iterator<InetAddress> getIPAddresses() throws DataUnavailable {
throw new DataUnavailable();
}
@Override
public long getInstalledMemory() throws DataUnavailable {
throw new DataUnavailable("Installed memory not available.");
}
@Override
public int getProcessorCount() throws DataUnavailable {
throw new DataUnavailable("Processor count not available.");
}
@Override
public String getProcessorSubType() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("Processor subtype not available.");
}
@Override
public String getProcessorType() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("Processor type not available");
}
@Override
public String getSystemSubType() throws DataUnavailable,
CorruptDataException {
throw new DataUnavailable("System subtype not available");
}
@Override
public String getSystemType() throws DataUnavailable, CorruptDataException {
throw new DataUnavailable("System type not available.");
}
@Override
public File getSource() {
return file;
}
}