annotate src/share/vm/code/compressedStream.hpp @ 1202:5f24d0319e54

4360113: Evict nmethods when code cache gets full Summary: Speculatively unload the oldest nmethods when code cache gets full. Reviewed-by: never, kvn Contributed-by: eric.caspole@amd.com
author kvn
date Fri, 29 Jan 2010 09:27:22 -0800
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // Simple interface for filing out and filing in basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // Used for writing out and reading in debugging information.
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 class CompressedStream : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
31 u_char* _buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 int _position;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Constants for UNSIGNED5 coding of Pack200
a61af66fc99e Initial load
duke
parents:
diff changeset
36 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
a61af66fc99e Initial load
duke
parents:
diff changeset
37 L = (1<<BitsPerByte)-H, // number of low codes (192)
a61af66fc99e Initial load
duke
parents:
diff changeset
38 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
39 };
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // these inlines are defined only in compressedStream.cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
42 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static inline juint reverse_int(juint bits); // to trim trailing float 0's
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 CompressedStream(u_char* buffer, int position = 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _buffer = buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _position = position;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 u_char* buffer() const { return _buffer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Positioning
a61af66fc99e Initial load
duke
parents:
diff changeset
55 int position() const { return _position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 void set_position(int position) { _position = position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 };
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 class CompressedReadStream : public CompressedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
62 inline u_char read() { return _buffer[_position++]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 jint read_int_mb(jint b0); // UNSIGNED5 coding, 2-5 byte cases
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 CompressedReadStream(u_char* buffer, int position = 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
68 : CompressedStream(buffer, position) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 jboolean read_bool() { return (jboolean) read(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 jbyte read_byte() { return (jbyte ) read(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 jchar read_char() { return (jchar ) read_int(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 jshort read_short() { return (jshort ) read_signed_int(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 jint read_int() { jint b0 = read();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if (b0 < L) return b0;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 else return read_int_mb(b0);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 jint read_signed_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 jfloat read_float(); // jfloat_cast(reverse_int(read_int()))
a61af66fc99e Initial load
duke
parents:
diff changeset
80 jdouble read_double(); // jdouble_cast(2*reverse_int(read_int))
a61af66fc99e Initial load
duke
parents:
diff changeset
81 jlong read_long(); // jlong_from(2*read_signed_int())
a61af66fc99e Initial load
duke
parents:
diff changeset
82 };
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 class CompressedWriteStream : public CompressedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bool full() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return _position >= _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 void store(u_char b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _buffer[_position++] = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 void write(u_char b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (full()) grow();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 store(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 void grow();
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
102 int _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
105 CompressedWriteStream(int initial_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
107 : CompressedStream(buffer, position) { _size = initial_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void write_bool(jboolean value) { write(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 void write_byte(jbyte value) { write(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void write_char(jchar value) { write_int(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void write_short(jshort value) { write_signed_int(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void write_int(jint value) { if ((juint)value < L && !full())
a61af66fc99e Initial load
duke
parents:
diff changeset
114 store((u_char)value);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 else write_int_mb(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void write_signed_int(jint value); // write_int(encode_sign(value))
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
a61af66fc99e Initial load
duke
parents:
diff changeset
119 void write_long(jlong value); // write_signed_int(<low,high>)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 };