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 IsCollectedDebuggee extends SyncDebuggee {
032:
033: static IsCollectedObject001_01 checkedObject_01;
034: static boolean checkedObject_01_Finalized = false;
035: static IsCollectedObject001_02 checkedObject_02;
036: static boolean checkedObject_02_Finalized = false;
037: static IsCollectedObject001_03 checkedObject_03;
038: static boolean checkedObject_03_Finalized = false;
039:
040: public void run() {
041: logWriter.println("--> Debuggee: IsCollectedDebuggee: START");
042:
043: checkedObject_01 = new IsCollectedObject001_01();
044: checkedObject_02 = new IsCollectedObject001_02();
045: checkedObject_03 = new IsCollectedObject001_03();
046:
047: synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
048: String messageFromTest = synchronizer.receiveMessage();
049: if (messageFromTest.equals("TO_FINISH")) {
050: logWriter
051: .println("--> Debuggee: IsCollectedDebuggee: FINISH");
052: return;
053: }
054:
055: checkedObject_01 = null;
056: checkedObject_02 = null;
057: checkedObject_03 = null;
058: long[][] longArray;
059: int i = 0;
060: try {
061: longArray = new long[1000000][];
062: int arraysNumberLimit = 7; // max - longArray.length
063: logWriter
064: .println("--> Debuggee: memory depletion - creating 'long[1000000]' arrays ("
065: + arraysNumberLimit + ")...");
066: for (; i < arraysNumberLimit; i++) {
067: longArray[i] = new long[1000000];
068: }
069: } catch (OutOfMemoryError outOfMem) {
070: logWriter.println("--> Debuggee: OutOfMemoryError!!!");
071: // logWriter.println("--> Debuggee: i = " + i);
072: }
073: longArray = null;
074: System.gc();
075: logWriter.println("--> Debuggee: AFTER System.gc():");
076: logWriter.println("--> Debuggee: checkedObject_01 = "
077: + checkedObject_01);
078: logWriter.println("--> Debuggee: checkedObject_01_UNLOADed = "
079: + checkedObject_01_Finalized);
080: logWriter.println("--> Debuggee: checkedObject_02 = "
081: + checkedObject_02);
082: logWriter.println("--> Debuggee: checkedObject_02_UNLOADed = "
083: + checkedObject_02_Finalized);
084: logWriter.println("--> Debuggee: checkedObject_03 = "
085: + checkedObject_03);
086: logWriter.println("--> Debuggee: checkedObject_03_UNLOADed = "
087: + checkedObject_03_Finalized);
088:
089: String messageForTest = null;
090: if (checkedObject_01_Finalized) {
091: if (checkedObject_02_Finalized) {
092: messageForTest = "checkedObject_01 is UNLOADed; checkedObject_02 is UNLOADed;";
093: } else {
094: messageForTest = "checkedObject_01 is UNLOADed; checkedObject_02 is NOT UNLOADed;";
095: }
096: } else {
097: if (checkedObject_02_Finalized) {
098: messageForTest = "checkedObject_01 is NOT UNLOADed; checkedObject_02 is UNLOADed;";
099: } else {
100: messageForTest = "checkedObject_01 is NOT UNLOADed; checkedObject_02 is NOT UNLOADed;";
101: }
102: }
103: logWriter.println("--> Debuggee: Send to test message: \""
104: + messageForTest + "\"");
105: synchronizer.sendMessage(messageForTest);
106: synchronizer
107: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
108:
109: logWriter.println("--> Debuggee: IsCollectedDebuggee: FINISH");
110:
111: }
112:
113: public static void main(String[] args) {
114: runDebuggee(IsCollectedDebuggee.class);
115: }
116:
117: }
118:
119: class IsCollectedObject001_01 {
120: protected void finalize() throws Throwable {
121: IsCollectedDebuggee.checkedObject_01_Finalized = true;
122: super .finalize();
123: }
124: }
125:
126: class IsCollectedObject001_02 {
127: protected void finalize() throws Throwable {
128: IsCollectedDebuggee.checkedObject_02_Finalized = true;
129: super .finalize();
130: }
131: }
132:
133: class IsCollectedObject001_03 {
134: protected void finalize() throws Throwable {
135: IsCollectedDebuggee.checkedObject_03_Finalized = true;
136: super.finalize();
137: }
138: }
|