This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 19936
Collapse All | Expand All

(-)CacheReference.java (-2 / +39 lines)
Lines 19-31 Link Here
19
/** A member of the MDR cache.  This is a soft reference to an object
19
/** A member of the MDR cache.  This is a soft reference to an object
20
* identified by a MOFID.
20
* identified by a MOFID.
21
*/
21
*/
22
class CacheReference extends SoftReference {
22
//class CacheReference extends SoftReference {
23
// BHM - lets try more memory friendly 
24
class CacheReference extends WeakReference {
23
25
24
    /* The MOF ID of the object we reference */
26
    /* The MOF ID of the object we reference */
25
    private Object key;
27
    private Object key;
28
    
29
    private Object hardRef;
26
30
27
    /* Whether the reference is currently in the cache */
31
    /* Whether the reference is currently in the cache */
28
    boolean inCache;
32
    // boolean inCache;
29
33
30
    /** Create a reference 
34
    /** Create a reference 
31
    * @param m the MOF ID of the referenced object
35
    * @param m the MOF ID of the referenced object
Lines 55-58 Link Here
55
        CacheReference cr = (CacheReference)o;
59
        CacheReference cr = (CacheReference)o;
56
        return cr.key.equals(key);
60
        return cr.key.equals(key);
57
    }
61
    }
62
    
63
    /** Calling this method makes the reference to be a hard reference
64
     */
65
    public void harden() {
66
        hardRef = get();
67
    }
68
    
69
    /** Calling this method makes the reference weak again
70
     */
71
    public void weaken() {
72
        hardRef = null;
73
    }
74
    
75
    /** Returns true if the reference is hard
76
     */
77
    public boolean isHard() {
78
        return hardRef != null;
79
    }
80
    
81
    
82
    /** Overriden clear to weaken possibly hardened reference
83
     */
84
    public void clear() {
85
        weaken();
86
        super.clear();
87
    }
88
    
89
    
90
    /** Returns the key of the referece */
91
    Object getKey() {
92
        return key;
93
    }
94
    
58
}
95
}
(-)MDRCache.java (-20 / +52 lines)
Lines 51-58 Link Here
51
    private HashMap hashOnId;
51
    private HashMap hashOnId;
52
52
53
    /* Hard references */
53
    /* Hard references */
54
    private Object hardRef[];
54
    //private Object hardRef[];
55
55
    private CacheReference hardRef[];
56
    
56
    /* current slot in above index */
57
    /* current slot in above index */
57
    private int hardIndex;
58
    private int hardIndex;
58
59
Lines 97-103 Link Here
97
    public MDRCache(int size) {
98
    public MDRCache(int size) {
98
        hashOnId = new HashMap();
99
        hashOnId = new HashMap();
99
        deleted = new HashMap();
100
        deleted = new HashMap();
100
        hardRef = new Object[size];
101
        //hardRef = new Object[size];
102
        hardRef = new CacheReference[size];
101
        hardIndex = 0;
103
        hardIndex = 0;
102
        queue = new ReferenceQueue();
104
        queue = new ReferenceQueue();
103
        dirty = new HashMap();
105
        dirty = new HashMap();
Lines 119-134 Link Here
119
    public synchronized void put(Object m, Object o) throws StorageException {
121
    public synchronized void put(Object m, Object o) throws StorageException {
120
        CacheReference cr = new CacheReference(m, o, queue);
122
        CacheReference cr = new CacheReference(m, o, queue);
121
        CacheReference oldCr = (CacheReference)hashOnId.put(m, cr);
123
        CacheReference oldCr = (CacheReference)hashOnId.put(m, cr);
122
        cr.inCache = true;
124
        //cr.inCache = true;
123
        if (oldCr != null) {
125
        if (oldCr != null) {
124
            oldCr.inCache = false;
126
            //oldCr.inCache = false;
125
            if (oldCr.get() != null && oldCr.get() != o) {
127
            if (oldCr.get() != null && oldCr.get() != o) {
126
                throw new StorageBadRequestException(
128
                throw new StorageBadRequestException(
127
                    MessageFormat.format("Duplicate MOF ID: {0}", 
129
                    MessageFormat.format("Duplicate MOF ID: {0}", 
128
                                         new Object[] {m} ));
130
                                         new Object[] {m} ));
129
            }
131
            }
132
            oldCr.clear();
130
        }
133
        }
131
        makeHardRef(o);
134
        //makeHardRef(o);
135
        makeHardRef(cr);
132
        checkQueue();
136
        checkQueue();
133
        int curSize = hashOnId.size();
137
        int curSize = hashOnId.size();
134
        if (curSize > maxSize)
138
        if (curSize > maxSize)
Lines 144-150 Link Here
144
        if (cr != null)
148
        if (cr != null)
145
            o = cr.get();
149
            o = cr.get();
146
        if (o != null) {
150
        if (o != null) {
147
            makeHardRef(o);
151
            makeHardRef(cr);
148
            hits++;
152
            hits++;
149
        }
153
        }
150
        else {
154
        else {
Lines 185-191 Link Here
185
189
186
        if (cr != null)  {
190
        if (cr != null)  {
187
            cr.clear();
191
            cr.clear();
188
            cr.inCache = false;
192
            //cr.inCache = false;
189
        }
193
        }
190
        boolean wasNew = (newOnes.remove(m) != null);
194
        boolean wasNew = (newOnes.remove(m) != null);
191
        dirty.remove(m);
195
        dirty.remove(m);
Lines 203-230 Link Here
203
    }
207
    }
204
208
205
    /* create a hard reference to the supplied object */
209
    /* create a hard reference to the supplied object */
206
    private void makeHardRef(Object o) {
210
    //private void makeHardRef(Object o) {
211
    private void makeHardRef(CacheReference cr) {    
212
        /**
207
        hardRef[hardIndex++] = o;
213
        hardRef[hardIndex++] = o;
208
        if (hardIndex >= hardRef.length) {
214
        if (hardIndex >= hardRef.length) {
209
            hardIndex = 0;
215
            hardIndex = 0;
210
        }
216
        }
217
        
218
        BHM: This was not very nice after 20 gets We'd have 20
219
             identical objects in the cache which definitely isn't
220
             what we want.
221
        */
222
        
223
        if ( cr.isHard() ) {
224
            // The reference is already in cache we don't need to do
225
            // anything
226
            return;
227
        }
228
        else {           
229
            if (hardRef[hardIndex] != null) {
230
                // Old Reference may be GCed 
231
                hardRef[hardIndex].weaken();
232
            }
233
            cr.harden();
234
            hardRef[hardIndex] = cr;
235
            
236
            hardIndex++;
237
            if ( hardIndex >= hardRef.length ) {
238
                hardIndex = 0;
239
            }
240
        }
211
    }
241
    }
212
242
213
    /* check for queued references, and remove them from the hash table */
243
    /* check for queued references, and remove them from the hash table */
214
    private void checkQueue() {
244
    private void checkQueue() {
215
//	int i = 0;
245
	int i = 0;
216
        CacheReference cr;
246
        CacheReference cr;
217
        while ((cr = (CacheReference)queue.poll()) != null) {
247
        while ((cr = (CacheReference)queue.poll()) != null) {
218
            if (cr.inCache) {
248
            //if (cr.inCache) {
219
                hashOnId.remove(cr);
249
            i += hashOnId.remove(cr.getKey()) == null ? 0 : 1;
220
                cr.inCache = false;
250
            // cr.inCache = false;
221
//		i++;
251
            //}
222
            }
252
        }
223
        }
253
        /*
224
//	if (i > 0) {
254
	if (i > 0) {
225
//	    System.out.println("Removed " + i + 
255
	    System.out.println("Removed " + i + 
226
//		" references; hash size now was " + (hashOnId.size() + i));
256
		" references; hash size now " + hashOnId.size() + " was " + (hashOnId.size() + i));
227
//	}
257
            System.out.println( " HardRefs " + hardIndex );
258
	}
259
        */
228
    }
260
    }
229
261
230
    /* Check to see if we have exceeded our threshhold for dirty objects
262
    /* Check to see if we have exceeded our threshhold for dirty objects

Return to bug 19936