Search in sources :

Example 21 with Image

use of com.ibm.dtfj.image.Image in project openj9 by eclipse.

the class ImageTest method getInstalledMemoryTest.

@Test
public void getInstalledMemoryTest() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        Image ddrImg = (Image) ddrTestObjects.get(i);
        Image jextractImg = (Image) jextractTestObjects.get(i);
        imageComparator.testEquals(ddrImg, jextractImg, ImageComparator.INSTALLED_MEMORY);
    }
}
Also used : Image(com.ibm.dtfj.image.Image) Test(org.junit.Test)

Example 22 with Image

use of com.ibm.dtfj.image.Image in project openj9 by eclipse.

the class ImageTest method getAddressSpaceTest.

@Test
public void getAddressSpaceTest() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        Image ddrImg = (Image) ddrTestObjects.get(i);
        Image jextractImg = (Image) jextractTestObjects.get(i);
        imageAddressSpaceComparator.testComparatorIteratorEquals(ddrImg, jextractImg, "getAddressSpaces", ImageAddressSpace.class);
    }
}
Also used : Image(com.ibm.dtfj.image.Image) Test(org.junit.Test)

Example 23 with Image

use of com.ibm.dtfj.image.Image in project openj9 by eclipse.

the class ImageTest method getHostNameTest.

@Test
public void getHostNameTest() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        Image ddrImg = (Image) ddrTestObjects.get(i);
        Image jextractImg = (Image) jextractTestObjects.get(i);
        imageComparator.testEquals(ddrImg, jextractImg, ImageComparator.HOST_NAME);
    }
}
Also used : Image(com.ibm.dtfj.image.Image) Test(org.junit.Test)

Example 24 with Image

use of com.ibm.dtfj.image.Image in project openj9 by eclipse.

the class DTFJImageFactory method getImage.

public Image getImage(final ImageInputStream in, final ImageInputStream meta, URI sourceID) throws IOException {
    /*
		 * Legacy core readers implement the ImageInputStream interface, but are backed by an implementation which
		 * is based around reading bytes directly from the stream without honouring the ByteOrder setting of the stream.
		 * This has the consequence that the readers expect all streams passes to them to be in BIG_ENDIAN order and
		 * then internally provide wrapper classes when LITTLE_ENDIAN is required. This is why the stream being
		 * passed has it's byte order fixed to BIG_ENDIAN.
		 */
    in.setByteOrder(ByteOrder.BIG_ENDIAN);
    ICoreFileReader core = DumpFactory.createDumpForCore(in);
    XMLIndexReader indexData = new XMLIndexReader();
    // downcast the image input stream to an input stream
    InputStream stream = new InputStream() {

        @Override
        public int read() throws IOException {
            return meta.read();
        }
    };
    // CMVC 154851 : pass the metadata stream through the new XML cleanup class
    XMLInputStream xmlstream = new XMLInputStream(stream);
    IFileLocationResolver resolver = null;
    File source = null;
    if ((sourceID.getFragment() != null) && (sourceID.getFragment().length() != 0)) {
        // need to strip any fragments from the URI which point to the core in the zip file
        try {
            URI uri = new URI(sourceID.getScheme() + "://" + sourceID.getPath());
            source = new File(uri);
        } catch (URISyntaxException e) {
        // if the URL cannot be constructed then assume it does not point to a file
        }
    } else {
        source = new File(sourceID);
    }
    if (source.exists()) {
        if (FileManager.isArchive(source)) {
            ZipFile zip = new ZipFile(source);
            resolver = new ZipExtractionResolver(zip);
        } else {
            resolver = new DefaultFileLocationResolver(source.getParentFile());
        }
    }
    ReleasingImage image = indexData.parseIndexWithDump(xmlstream, core, in, resolver);
    // close access to the XML file as we won't be needing it again
    meta.close();
    // because the IIS is used to derive the core reader only the reader needs to be added as a ReleasingResource
    image.addReleasable(core);
    if (image instanceof com.ibm.dtfj.image.j9.Image) {
        ((com.ibm.dtfj.image.j9.Image) image).SetSource(sourceID);
    }
    return image;
}
Also used : XMLInputStream(com.ibm.jvm.j9.dump.indexsupport.XMLInputStream) FileInputStream(java.io.FileInputStream) XMLInputStream(com.ibm.jvm.j9.dump.indexsupport.XMLInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) Image(com.ibm.dtfj.image.Image) URI(java.net.URI) ICoreFileReader(com.ibm.dtfj.corereaders.ICoreFileReader) XMLIndexReader(com.ibm.jvm.j9.dump.indexsupport.XMLIndexReader) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 25 with Image

use of com.ibm.dtfj.image.Image in project openj9 by eclipse.

the class ImageFactory method getImagesFromArchive.

@Override
public Image[] getImagesFromArchive(File archive, boolean extract) throws IOException {
    Objects.requireNonNull(archive);
    if (!FileManager.fileExists(archive)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new FileNotFoundException("Archive '" + archive.getAbsolutePath() + "' not found.");
    }
    if (!FileManager.isArchive(archive)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new IOException("The specified archive " + archive.getAbsolutePath() + " was not recognised");
    }
    // images created from this zip file
    ArrayList<Image> images = new ArrayList<>();
    exceptions.clear();
    // the cast to an ArchiveFileManager is safe as we've already checked earlier with FileManager.isArchive
    CompressedFileManager manager = (CompressedFileManager) FileManager.getManager(archive);
    List<ManagedImageSource> sources = manager.getImageSources();
    if (extract) {
        // create the temporary directory in preparation for the extraction
        File parent = getTempDirParent();
        tmpdir = FileManager.createTempDir(parent);
    }
    for (ManagedImageSource source : sources) {
        ImageInputStream corestream = null;
        ImageInputStream metastream = null;
        if (extract) {
            // extract the files to disk
            manager.extract(source, tmpdir);
            File coreFile = new File(source.getPathToExtractedFile());
            corestream = new J9FileImageInputStream(coreFile, source);
            if (source.hasMetaData()) {
                manager.extract(source.getMetadata(), tmpdir);
                File metaFile = new File(source.getMetadata().getPathToExtractedFile());
                metastream = new J9FileImageInputStream(metaFile, source.getMetadata());
            }
        } else {
            // run from in memory
            corestream = manager.getStream(source);
            if (source.hasMetaData()) {
                metastream = manager.getStream(source.getMetadata());
            }
        }
        try {
            // Try each factory listed for this source file type, checking to see if we find a JRE
            ImageReference imageReference = new ImageReference();
            for (String factory : source.getType().getFactoryNames()) {
                if (foundRuntimeInImage(factory, imageReference, source.toURI(), corestream, metastream)) {
                    if (imageReference.image instanceof ManagedImage) {
                        ((ManagedImage) imageReference.image).setImageSource(source);
                    }
                    images.add(imageReference.image);
                    // quit looking for an image
                    break;
                }
                imageReference.image = null;
            }
            // Final fallback is to get a native-only DDR Image (no JRE), if the source is a core dump
            if (imageReference.image == null && source.getType().equals(ImageSourceType.CORE)) {
                com.ibm.dtfj.image.ImageFactory factory = createImageFactory(FACTORY_DDR);
                if (factory != null) {
                    imageReference.image = factory.getImage(corestream, source.toURI());
                    if (imageReference.image != null) {
                        images.add(imageReference.image);
                    }
                }
            }
        } catch (Exception e) {
            // log exception and attempt to carry on creating images
            exceptions.add(e);
        }
    }
    printExceptions();
    return images.toArray(new Image[images.size()]);
}
Also used : ManagedImage(com.ibm.dtfj.utils.ManagedImage) J9FileImageInputStream(com.ibm.dtfj.utils.file.J9FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) J9FileImageInputStream(com.ibm.dtfj.utils.file.J9FileImageInputStream) Image(com.ibm.dtfj.image.Image) ManagedImage(com.ibm.dtfj.utils.ManagedImage) MultipleCandidateException(com.ibm.dtfj.utils.file.MultipleCandidateException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ManagedImageSource(com.ibm.dtfj.utils.file.ManagedImageSource) CompressedFileManager(com.ibm.dtfj.utils.file.CompressedFileManager) File(java.io.File)

Aggregations

Image (com.ibm.dtfj.image.Image)27 Test (org.junit.Test)10 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)7 ImageFactory (com.ibm.dtfj.image.ImageFactory)7 File (java.io.File)7 ImageProcess (com.ibm.dtfj.image.ImageProcess)6 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)6 IOException (java.io.IOException)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)5 Iterator (java.util.Iterator)4 ImageInputStream (javax.imageio.stream.ImageInputStream)4 CorruptData (com.ibm.dtfj.image.CorruptData)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageModule (com.ibm.dtfj.image.ImageModule)2 ImageBuilderFactory (com.ibm.dtfj.javacore.builder.javacore.ImageBuilderFactory)2 JavaCoreReader (com.ibm.dtfj.javacore.parser.j9.JavaCoreReader)2 FileNotFoundException (java.io.FileNotFoundException)2 ICoreFileReader (com.ibm.dtfj.corereaders.ICoreFileReader)1