3666 // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat |
3663 // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat |
3667 // counter defined in runtimeService.cpp. |
3664 // counter defined in runtimeService.cpp. |
3668 info->is_attachable = AttachListener::is_attach_supported(); |
3665 info->is_attachable = AttachListener::is_attach_supported(); |
3669 } |
3666 } |
3670 JVM_END |
3667 JVM_END |
3671 |
|
3672 // jdk.internal.jimage ///////////////////////////////////////////////////////// |
|
3673 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3674 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3675 |
|
3676 // Java entry to open an image file for sharing. |
|
3677 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3678 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3679 JVM_ENTRY(jlong, |
|
3680 JVM_ImageOpen(JNIEnv *env, const char *nativePath, jboolean big_endian)) { |
|
3681 JVMWrapper("JVM_ImageOpen"); |
|
3682 // Open image file for reading. |
|
3683 ImageFileReader* reader = ImageFileReader::open(nativePath, big_endian != JNI_FALSE); |
|
3684 // Return image ID as a jlong. |
|
3685 return ImageFileReader::readerToID(reader); |
|
3686 } |
|
3687 JVM_END |
|
3688 |
|
3689 // Java entry for closing a shared image file. |
|
3690 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3691 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3692 JVM_ENTRY(void, |
|
3693 JVM_ImageClose(JNIEnv *env, jlong id)) { |
|
3694 JVMWrapper("JVM_ImageClose"); |
|
3695 // Convert image ID to image reader structure. |
|
3696 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3697 // If valid reader the close. |
|
3698 if (reader != NULL) { |
|
3699 ImageFileReader::close(reader); |
|
3700 } |
|
3701 } |
|
3702 JVM_END |
|
3703 |
|
3704 // Java entry for accessing the base address of the image index. |
|
3705 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3706 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3707 JVM_ENTRY(jlong, |
|
3708 JVM_ImageGetIndexAddress(JNIEnv *env, jlong id)) { |
|
3709 JVMWrapper("JVM_ImageGetIndexAddress"); |
|
3710 // Convert image ID to image reader structure. |
|
3711 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3712 // If valid reader return index base address (as jlong) else zero. |
|
3713 return reader != NULL ? (jlong)reader->get_index_address() : 0L; |
|
3714 } |
|
3715 JVM_END |
|
3716 |
|
3717 // Java entry for accessing the base address of the image data. |
|
3718 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3719 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3720 JVM_ENTRY(jlong, |
|
3721 JVM_ImageGetDataAddress(JNIEnv *env, jlong id)) { |
|
3722 JVMWrapper("JVM_ImageGetDataAddress"); |
|
3723 // Convert image ID to image reader structure. |
|
3724 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3725 // If valid reader return data base address (as jlong) else zero. |
|
3726 return MemoryMapImage && reader != NULL ? (jlong)reader->get_data_address() : 0L; |
|
3727 } |
|
3728 JVM_END |
|
3729 |
|
3730 // Java entry for reading an uncompressed resource from the image. |
|
3731 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3732 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3733 JVM_ENTRY(jboolean, |
|
3734 JVM_ImageRead(JNIEnv *env, jlong id, jlong offset, |
|
3735 unsigned char* uncompressedAddress, jlong uncompressed_size)) { |
|
3736 JVMWrapper("JVM_ImageRead"); |
|
3737 // Convert image ID to image reader structure. |
|
3738 ImageFileReader* reader = ImageFileReader::idToReader(id);\ |
|
3739 // If not a valid reader the fail the read. |
|
3740 if (reader == NULL) return false; |
|
3741 // Get the file offset of resource data. |
|
3742 u8 file_offset = reader->get_index_size() + offset; |
|
3743 // Check validity of arguments. |
|
3744 if (offset < 0 || |
|
3745 uncompressed_size < 0 || |
|
3746 file_offset > reader->file_size() - uncompressed_size) { |
|
3747 return false; |
|
3748 } |
|
3749 // Read file content into buffer. |
|
3750 return (jboolean)reader->read_at((u1*)uncompressedAddress, uncompressed_size, |
|
3751 file_offset); |
|
3752 } |
|
3753 JVM_END |
|
3754 |
|
3755 // Java entry for reading a compressed resource from the image. |
|
3756 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3757 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3758 JVM_ENTRY(jboolean, |
|
3759 JVM_ImageReadCompressed(JNIEnv *env, |
|
3760 jlong id, jlong offset, |
|
3761 unsigned char* compressedAddress, jlong compressed_size, |
|
3762 unsigned char* uncompressedAddress, jlong uncompressed_size)) { |
|
3763 JVMWrapper("JVM_ImageReadCompressed"); |
|
3764 // Convert image ID to image reader structure. |
|
3765 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3766 // If not a valid reader the fail the read. |
|
3767 if (reader == NULL) return false; |
|
3768 // Get the file offset of resource data. |
|
3769 u8 file_offset = reader->get_index_size() + offset; |
|
3770 // Check validity of arguments. |
|
3771 if (offset < 0 || |
|
3772 compressed_size < 0 || |
|
3773 uncompressed_size < 0 || |
|
3774 file_offset > reader->file_size() - compressed_size) { |
|
3775 return false; |
|
3776 } |
|
3777 |
|
3778 // Read file content into buffer. |
|
3779 bool is_read = reader->read_at(compressedAddress, compressed_size, |
|
3780 file_offset); |
|
3781 // If successfully read then decompress. |
|
3782 if (is_read) { |
|
3783 const ImageStrings strings = reader->get_strings(); |
|
3784 ImageDecompressor::decompress_resource(compressedAddress, uncompressedAddress, |
|
3785 uncompressed_size, &strings, true); |
|
3786 } |
|
3787 return (jboolean)is_read; |
|
3788 } |
|
3789 JVM_END |
|
3790 |
|
3791 // Java entry for retrieving UTF-8 bytes from image string table. |
|
3792 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3793 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3794 JVM_ENTRY(const char*, JVM_ImageGetStringBytes(JNIEnv *env, jlong id, jint offset)) { |
|
3795 JVMWrapper("JVM_ImageGetStringBytes"); |
|
3796 // Convert image ID to image reader structure. |
|
3797 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3798 // Fail if not valid reader. |
|
3799 if (reader == NULL) return NULL; |
|
3800 // Manage image string table. |
|
3801 ImageStrings strings = reader->get_strings(); |
|
3802 // Retrieve string adrress from table. |
|
3803 const char* data = strings.get(offset); |
|
3804 return data; |
|
3805 } |
|
3806 JVM_END |
|
3807 |
|
3808 // Utility function to copy location information into a jlong array. |
|
3809 // WARNING: This function is experimental and temporary during JDK 9 development |
|
3810 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3811 static void image_expand_location(JNIEnv *env, jlong* rawAttributes, ImageLocation& location) { |
|
3812 // Copy attributes from location. |
|
3813 for (int kind = ImageLocation::ATTRIBUTE_END + 1; |
|
3814 kind < ImageLocation::ATTRIBUTE_COUNT; |
|
3815 kind++) { |
|
3816 rawAttributes[kind] = location.get_attribute(kind); |
|
3817 } |
|
3818 } |
|
3819 |
|
3820 // Java entry for retrieving location attributes for attribute offset. |
|
3821 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3822 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3823 JVM_ENTRY(jlong*, JVM_ImageGetAttributes(JNIEnv *env, jlong* rawAttributes, jlong id, jint offset)) { |
|
3824 JVMWrapper("JVM_ImageGetAttributes"); |
|
3825 // Convert image ID to image reader structure. |
|
3826 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3827 // Fail if not valid reader. |
|
3828 if (reader == NULL) return NULL; |
|
3829 // Retrieve first byte address of resource's location attribute stream. |
|
3830 u1* data = reader->get_location_offset_data(offset); |
|
3831 // Fail if not valid offset. |
|
3832 if (data == NULL) return NULL; |
|
3833 // Expand stream into array. |
|
3834 ImageLocation location(data); |
|
3835 image_expand_location(env, rawAttributes, location); |
|
3836 return rawAttributes; |
|
3837 } |
|
3838 JVM_END |
|
3839 |
|
3840 // Java entry for retrieving location attributes count for attribute offset. |
|
3841 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3842 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3843 JVM_ENTRY(jsize, JVM_ImageGetAttributesCount(JNIEnv *env)) { |
|
3844 JVMWrapper("JVM_ImageGetAttributesCount"); |
|
3845 return ImageLocation::ATTRIBUTE_COUNT; |
|
3846 } |
|
3847 JVM_END |
|
3848 |
|
3849 // Java entry for retrieving location attributes for named resource. |
|
3850 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3851 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3852 JVM_ENTRY(jlong*, |
|
3853 JVM_ImageFindAttributes(JNIEnv *env, jlong* rawAttributes, jbyte* rawBytes, jsize size, jlong id)) { |
|
3854 JVMWrapper("JVM_ImageFindAttributes"); |
|
3855 // Mark for temporary buffers. |
|
3856 ResourceMark rm; |
|
3857 // Convert image ID to image reader structure. |
|
3858 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3859 // Fail if not valid reader. |
|
3860 if (reader == NULL) return NULL; |
|
3861 // Convert byte array to a cstring. |
|
3862 char* path = NEW_RESOURCE_ARRAY(char, size + 1); |
|
3863 memcpy(path, rawBytes, size); |
|
3864 path[size] = '\0'; |
|
3865 // Locate resource location data. |
|
3866 ImageLocation location; |
|
3867 bool found = reader->find_location(path, location); |
|
3868 // Resource not found. |
|
3869 if (!found) return NULL; |
|
3870 // Expand stream into array. |
|
3871 image_expand_location(env, rawAttributes, location); |
|
3872 return rawAttributes; |
|
3873 } |
|
3874 JVM_END |
|
3875 |
|
3876 // Java entry for retrieving all the attribute stream offsets from an image. |
|
3877 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3878 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3879 JVM_ENTRY(jint*, JVM_ImageAttributeOffsets(JNIEnv *env, jint* rawOffsets, unsigned int length, jlong id)) { |
|
3880 JVMWrapper("JVM_ImageAttributeOffsets"); |
|
3881 // Convert image ID to image reader structure. |
|
3882 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3883 // Fail if not valid reader. |
|
3884 if (reader == NULL) return NULL; |
|
3885 // Determine endian for reader. |
|
3886 Endian* endian = reader->endian(); |
|
3887 // Get base address of attribute stream offsets table. |
|
3888 u4* offsets_table = reader->offsets_table(); |
|
3889 // Allocate int array result. |
|
3890 // Copy values to result (converting endian.) |
|
3891 for (u4 i = 0; i < length; i++) { |
|
3892 rawOffsets[i] = endian->get(offsets_table[i]); |
|
3893 } |
|
3894 return rawOffsets; |
|
3895 } |
|
3896 JVM_END |
|
3897 |
|
3898 // Java entry for retrieving all the attribute stream offsets length from an image. |
|
3899 // WARNING: This API is experimental and temporary during JDK 9 development |
|
3900 // cycle. It will not be supported in the eventual JDK 9 release. |
|
3901 JVM_ENTRY(unsigned int, JVM_ImageAttributeOffsetsLength(JNIEnv *env, jlong id)) { |
|
3902 JVMWrapper("JVM_ImageAttributeOffsetsLength"); |
|
3903 // Convert image ID to image reader structure. |
|
3904 ImageFileReader* reader = ImageFileReader::idToReader(id); |
|
3905 // Fail if not valid reader. |
|
3906 if (reader == NULL) return 0; |
|
3907 // Get perfect hash table length. |
|
3908 u4 length = reader->table_length(); |
|
3909 return (jint) length; |
|
3910 } |
|
3911 JVM_END |
|