001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anatoly F. Bondarenko
021: * @version $Revision: 1.3 $
022: */
023:
024: /**
025: * Created on 04.03.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ObjectReference;
027:
028: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
029: import org.apache.harmony.jpda.tests.share.SyncDebuggee;
030:
031: public class DisableCollectionDebuggee extends SyncDebuggee {
032:
033: static DisableCollectionObject001_01 checkedObject;
034: static boolean checkedObject_Finalized = false;
035: static DisableCollectionObject001_02 patternObject;
036: static boolean patternObject_Finalized = false;
037:
038: public void run() {
039: logWriter
040: .println("--> Debuggee: DisableCollectionDebuggee: START");
041:
042: checkedObject = new DisableCollectionObject001_01();
043: patternObject = new DisableCollectionObject001_02();
044:
045: synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
046: String messageFromTest = synchronizer
047: .receiveMessageWithoutException("DisableCollectionDebuggee(#1)");
048: logWriter.println("--> messageFromTest = |" + messageFromTest
049: + "|");
050: if (messageFromTest.equals("TO_FINISH")) {
051: logWriter
052: .println("--> Debuggee: DisableCollectionDebuggee: FINISH");
053: return;
054: }
055:
056: logWriter.println("--> Debuggee: BEFORE System.gc():");
057: logWriter.println("--> Debuggee: checkedObject = "
058: + checkedObject);
059: logWriter.println("--> Debuggee: checkedObject_UNLOADed = "
060: + checkedObject_Finalized);
061: logWriter.println("--> Debuggee: patternObject = "
062: + patternObject);
063: logWriter.println("--> Debuggee: patternObject_UNLOADed = "
064: + patternObject_Finalized);
065:
066: checkedObject = null;
067: patternObject = null;
068: long[][] longArray;
069: int i = 0;
070: try {
071: longArray = new long[1000000][];
072: int arraysNumberLimit = 7; // max - longArray.length
073: logWriter
074: .println("--> Debuggee: memory depletion - creating 'long[1000000]' arrays ("
075: + arraysNumberLimit + ")...");
076: for (; i < arraysNumberLimit; i++) {
077: longArray[i] = new long[1000000];
078: }
079: } catch (OutOfMemoryError outOfMem) {
080: logWriter.println("--> Debuggee: OutOfMemoryError!!!");
081: // logWriter.println("--> Debuggee: i = " + i);
082: }
083: longArray = null;
084: System.gc();
085: logWriter.println("--> Debuggee: AFTER System.gc():");
086: logWriter.println("--> Debuggee: checkedObject = "
087: + checkedObject);
088: logWriter.println("--> Debuggee: checkedObject_UNLOADed = "
089: + checkedObject_Finalized);
090: logWriter.println("--> Debuggee: patternObject = "
091: + patternObject);
092: logWriter.println("--> Debuggee: patternObject_UNLOADed = "
093: + patternObject_Finalized);
094:
095: String messageForTest = null;
096: if (checkedObject_Finalized) {
097: messageForTest = "Checked Object is UNLOADed!";
098: } else {
099: messageForTest = "Checked Object is NOT UNLOADed!";
100: }
101: logWriter.println("--> Debuggee: Send to test message: \""
102: + messageForTest + "\"");
103: synchronizer.sendMessage(messageForTest);
104: synchronizer
105: .receiveMessageWithoutException("DisableCollectionDebuggee(#2)");
106:
107: logWriter
108: .println("--> Debuggee: DisableCollectionDebuggee: FINISH");
109:
110: }
111:
112: public static void main(String[] args) {
113: runDebuggee(DisableCollectionDebuggee.class);
114: }
115:
116: }
117:
118: class DisableCollectionObject001_01 {
119: protected void finalize() throws Throwable {
120: DisableCollectionDebuggee.checkedObject_Finalized = true;
121: super .finalize();
122: }
123: }
124:
125: class DisableCollectionObject001_02 {
126: protected void finalize() throws Throwable {
127: DisableCollectionDebuggee.patternObject_Finalized = true;
128: super.finalize();
129: }
130: }
|