src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/SoftReferenceGrammarPool.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * reserved comment block |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT REMOVE OR ALTER! |
3 * @LastModified: Oct 2017 |
4 */ |
4 */ |
5 /* |
5 /* |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * Licensed to the Apache Software Foundation (ASF) under one or more |
7 * contributor license agreements. See the NOTICE file distributed with |
7 * contributor license agreements. See the NOTICE file distributed with |
8 * this work for additional information regarding copyright ownership. |
8 * this work for additional information regarding copyright ownership. |
63 |
63 |
64 /** The number of grammars in the pool */ |
64 /** The number of grammars in the pool */ |
65 protected int fGrammarCount = 0; |
65 protected int fGrammarCount = 0; |
66 |
66 |
67 /** Reference queue for cleared grammar references */ |
67 /** Reference queue for cleared grammar references */ |
68 protected final ReferenceQueue fReferenceQueue = new ReferenceQueue(); |
68 protected final ReferenceQueue<Grammar> fReferenceQueue = new ReferenceQueue<>(); |
69 |
69 |
70 // |
70 // |
71 // Constructors |
71 // Constructors |
72 // |
72 // |
73 |
73 |
368 |
368 |
369 /** |
369 /** |
370 * Removes stale entries from the pool. |
370 * Removes stale entries from the pool. |
371 */ |
371 */ |
372 private void clean() { |
372 private void clean() { |
373 Reference ref = fReferenceQueue.poll(); |
373 Reference<? extends Grammar> ref = fReferenceQueue.poll(); |
374 while (ref != null) { |
374 while (ref != null) { |
375 Entry entry = ((SoftGrammarReference) ref).entry; |
375 Entry entry = ((SoftGrammarReference) ref).entry; |
376 if (entry != null) { |
376 if (entry != null) { |
377 removeEntry(entry); |
377 removeEntry(entry); |
378 } |
378 } |
391 public Entry prev; |
391 public Entry prev; |
392 public Entry next; |
392 public Entry next; |
393 public XMLGrammarDescription desc; |
393 public XMLGrammarDescription desc; |
394 public SoftGrammarReference grammar; |
394 public SoftGrammarReference grammar; |
395 |
395 |
396 protected Entry(int hash, int bucket, XMLGrammarDescription desc, Grammar grammar, Entry next, ReferenceQueue queue) { |
396 protected Entry(int hash, int bucket, XMLGrammarDescription desc, Grammar grammar, |
|
397 Entry next, ReferenceQueue<Grammar> queue) { |
397 this.hash = hash; |
398 this.hash = hash; |
398 this.bucket = bucket; |
399 this.bucket = bucket; |
399 this.prev = null; |
400 this.prev = null; |
400 this.next = next; |
401 this.next = next; |
401 if (next != null) { |
402 if (next != null) { |
420 |
421 |
421 /** |
422 /** |
422 * This class stores a soft reference to a grammar object. It keeps a reference |
423 * This class stores a soft reference to a grammar object. It keeps a reference |
423 * to its associated entry, so that it can be easily removed from the pool. |
424 * to its associated entry, so that it can be easily removed from the pool. |
424 */ |
425 */ |
425 static final class SoftGrammarReference extends SoftReference { |
426 static final class SoftGrammarReference extends SoftReference<Grammar> { |
426 |
427 |
427 public Entry entry; |
428 public Entry entry; |
428 |
429 |
429 protected SoftGrammarReference(Entry entry, Grammar grammar, ReferenceQueue queue) { |
430 protected SoftGrammarReference(Entry entry, Grammar grammar, ReferenceQueue<Grammar> queue) { |
430 super(grammar, queue); |
431 super(grammar, queue); |
431 this.entry = entry; |
432 this.entry = entry; |
432 } |
433 } |
433 |
434 |
434 } // class SoftGrammarReference |
435 } // class SoftGrammarReference |