author | jlaskey |
Fri, 04 Sep 2015 10:11:43 -0300 | |
changeset 32641 | ac2c73b45253 |
child 32757 | 79d34d4b9627 |
permissions | -rw-r--r-- |
32641
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
1 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
4 |
* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
8 |
* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
13 |
* accompanied this code). |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
14 |
* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
18 |
* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
21 |
* questions. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
22 |
* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
23 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
24 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
25 |
#ifndef LIBJIMAGE_IMAGEDECOMPRESSOR_HPP |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
26 |
#define LIBJIMAGE_IMAGEDECOMPRESSOR_HPP |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
27 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
28 |
#include <assert.h> |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
29 |
#include <string.h> |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
30 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
31 |
#include "imageFile.hpp" |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
32 |
#include "inttypes.hpp" |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
33 |
#include "jni.h" |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
34 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
35 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
36 |
* Compressed resources located in image have an header. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
37 |
* This header contains: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
38 |
* - _magic: A magic u4, required to retrieved the header in the compressed content |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
39 |
* - _size: The size of the compressed resource. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
40 |
* - _uncompressed_size: The uncompressed size of the compressed resource. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
41 |
* - _decompressor_name_offset: The ImageDecompressor instance name StringsTable offset. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
42 |
* - _decompressor_config_offset: StringsTable offset of configuration that could be needed by |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
43 |
* the decompressor in order to decompress. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
44 |
* - _is_terminal: 1: the compressed content is terminal. Uncompressing it would |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
45 |
* create the actual resource. 0: the compressed content is not terminal. Uncompressing it |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
46 |
* will result in a compressed content to be decompressed (This occurs when a stack of compressors |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
47 |
* have been used to compress the resource. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
48 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
49 |
struct ResourceHeader { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
50 |
/* Length of header, needed to retrieve content offset */ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
51 |
static const u1 resource_header_length = 21; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
52 |
/* magic bytes that identifies a compressed resource header*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
53 |
static const u4 resource_header_magic = 0xCAFEFAFA; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
54 |
u4 _magic; // Resource header |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
55 |
u4 _size; // Resource size |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
56 |
u4 _uncompressed_size; // Expected uncompressed size |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
57 |
u4 _decompressor_name_offset; // Strings table decompressor offset |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
58 |
u4 _decompressor_config_offset; // Strings table config offset |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
59 |
u1 _is_terminal; // Last decompressor 1, otherwise 0. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
60 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
61 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
62 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
63 |
* Resources located in jimage file can be compressed. Compression occurs at |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
64 |
* jimage file creation time. When compressed a resource is added an header that |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
65 |
* contains the name of the compressor that compressed it. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
66 |
* Various compression strategies can be applied to compress a resource. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
67 |
* The same resource can even be compressed multiple time by a stack of compressors. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
68 |
* At runtime, a resource is decompressed in a loop until there is no more header |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
69 |
* meaning that the resource is equivalent to the not compressed resource. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
70 |
* In each iteration, the name of the compressor located in the current header |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
71 |
* is used to retrieve the associated instance of ImageDecompressor. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
72 |
* For example “zip” is the name of the compressor that compresses resources |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
73 |
* using the zip algorithm. The ZipDecompressor class name is also “zip”. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
74 |
* ImageDecompressor instances are retrieved from a static array in which |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
75 |
* they are registered. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
76 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
77 |
class ImageDecompressor { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
78 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
79 |
private: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
80 |
const char* _name; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
81 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
82 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
83 |
* Array of concrete decompressors. This array is used to retrieve the decompressor |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
84 |
* that can handle resource decompression. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
85 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
86 |
static ImageDecompressor** _decompressors; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
87 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
88 |
* Num of decompressors |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
89 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
90 |
static int _decompressors_num; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
91 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
92 |
* Identifier of a decompressor. This name is the identification key to retrieve |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
93 |
* decompressor from a resource header. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
94 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
95 |
inline const char* get_name() const { return _name; } |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
96 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
97 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
98 |
protected: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
99 |
ImageDecompressor(const char* name) : _name(name) { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
100 |
} |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
101 |
virtual void decompress_resource(u1* data, u1* uncompressed, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
102 |
ResourceHeader* header, const ImageStrings* strings) = 0; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
103 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
104 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
105 |
static void image_decompressor_init(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
106 |
static void image_decompressor_close(); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
107 |
static ImageDecompressor* get_decompressor(const char * decompressor_name) ; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
108 |
static void decompress_resource(u1* compressed, u1* uncompressed, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
109 |
u4 uncompressed_size, const ImageStrings* strings); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
110 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
111 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
112 |
/** |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
113 |
* Zip decompressor. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
114 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
115 |
class ZipDecompressor : public ImageDecompressor { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
116 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
117 |
ZipDecompressor(const char* sym) : ImageDecompressor(sym) { } |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
118 |
void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
119 |
const ImageStrings* strings); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
120 |
static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
121 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
122 |
|
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
123 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
124 |
* Shared Strings decompressor. This decompressor reconstruct the class |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
125 |
* constant pool UTF_U entries by retrieving strings stored in jimage strings table. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
126 |
* In addition, if the UTF_8 entry is a descriptor, the descriptor has to be rebuilt, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
127 |
* all java type having been removed from the descriptor and added to the sting table. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
128 |
* eg: "(Ljava/lang/String;I)V" ==> "(L;I)V" and "java/lang", "String" |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
129 |
* stored in string table. offsets to the 2 strings are compressed and stored in the |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
130 |
* constantpool entry. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
131 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
132 |
class SharedStringDecompressor : public ImageDecompressor { |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
133 |
private: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
134 |
// the constant pool tag for UTF8 string located in strings table |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
135 |
static const int externalized_string = 23; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
136 |
// the constant pool tag for UTF8 descriptors string located in strings table |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
137 |
static const int externalized_string_descriptor = 25; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
138 |
// the constant pool tag for UTF8 |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
139 |
static const int constant_utf8 = 1; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
140 |
// the constant pool tag for long |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
141 |
static const int constant_long = 5; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
142 |
// the constant pool tag for double |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
143 |
static const int constant_double = 6; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
144 |
// array index is the constant pool tag. value is size. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
145 |
// eg: array[5] = 8; means size of long is 8 bytes. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
146 |
static const u1 sizes[]; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
147 |
// bit 5 and 6 are used to store the length of the compressed integer. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
148 |
// size can be 1 (01), 2 (10), 3 (11). |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
149 |
// 0x60 ==> 0110000 |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
150 |
static const int compressed_index_size_mask = 0x60; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
151 |
/* |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
152 |
* mask the length bits (5 and 6) and move to the right 5 bits. |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
153 |
*/ |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
154 |
inline static int get_compressed_length(char c) { return ((char) (c & compressed_index_size_mask) >> 5); } |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
155 |
inline static bool is_compressed(signed char b1) { return b1 < 0; } |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
156 |
static int decompress_int(unsigned char*& value); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
157 |
public: |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
158 |
SharedStringDecompressor(const char* sym) : ImageDecompressor(sym){} |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
159 |
void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
160 |
const ImageStrings* strings); |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
161 |
}; |
ac2c73b45253
8087181: Move native jimage code to its own library (maybe libjimage)
jlaskey
parents:
diff
changeset
|
162 |
#endif // LIBJIMAGE_IMAGEDECOMPRESSOR_HPP |